Create Login API in C# ASP.NET VS 2010Yogesh Sharma10yAsked Feb 24, 2016, 11:29 PM ESTSolvedShareLinkedInXCopy linkSaveDear all friends,,, I want create simple login web form.... But i want check userid and password through API.... So, please suggest me how to handle this type task...
Create Login API in C# ASP.NET VS 2010Yogesh Sharma10yAsked Feb 24, 2016, 11:29 PM ESTSolvedShareLinkedInXCopy linkSaveDear all friends,,, I want create simple login web form.... But i want check userid and password through API.... So, please suggest me how to handle this type task...
Amit Kumar SinghRank #562 · 4.3K reputation10y agoPosted Feb 25, 2016, 1:36 AM EST✓ Accepted answer0http://www.c-sharpcorner.com/UploadFile/2b481f/simple-login-form-in-web-api/0
Amit KumarRank #459 · 5.4K reputation10y agoPosted Feb 24, 2016, 11:59 PM EST0Hi Yogesh, Create a MVC application. First take a model class : namespace MvcApplicationLogin.Models{ public class LoginModel { public string UName { get; set; } public string UPassword { get; set; } }} Create its view : function showlog() { if ($("#txtuname").attr("value") == "") { alert("Please enter user name."); return false; } else if ($("#txtu password").attr("value") == "") { alert("Please enter Password."); return false; } alert("Login Successfully"); return true; } @using (Html.BeginForm("Index", "Home")){ User Name : @Html.TextBoxFor(m => m.UName, new {@style="width:100px",@id="txtuname" }) User Password : @Html.PasswordFor(m => m.U Password, new {@style="width:100px",@id="txtupassword" }) } Create your controller here like: public class HomeController : Controller { public ActionResult Index() {//Create loginModel object here LoginModel obj = new LoginModel(); return View(obj); //For bind the view } //when user enter usernaem and password after that this event is fire.. [HttpPost] public ActionResult Index(LoginModel usrlogin) {if(Convert.ToString(dt.rows(0)("0"))=usrlogin.UName && Convert.ToString(dt.rows(0)("1"))=usrlogin.UPassword){ ViewBag.Status = " Login successfully."; } else { ViewBag.Status = "Incorrect user name and password."; } return View(usrlogin); } Public static DataTable Ulogin(){ DataTable dt =new DataTable();dt=fetch data from database return dt; } Please use it.. 0Yogesh Sharma123 reputation10y agoPosted Feb 25, 2016, 12:03 AM EST0Thanks for your quick reply.... But, i want to check userid and password from sql table... 0Amit KumarRank #459 · 5.4K reputation10y agoPosted Feb 25, 2016, 12:13 AM EST0Ok , Check it my above Post again ... I have use database for login... 0Amit Kumar SinghRank #562 · 4.3K reputation10y agoPosted Feb 25, 2016, 12:15 AM EST0IF EXISTS(SELECT USERID,PASSWORD FROM EMPLOYEE WHERE USERID=@USERID AND PASSWORD=@PASSWORD) BEGIN SELECT 'LOGIN WAS SUCCESSFULLY' ENDELSE BEGIN SELECT 'USERID AND PASSWORD WAS INCORRECT' END0Krishna Rajput SinghRank #605 · 4K reputation10y agoPosted Feb 25, 2016, 12:34 AM EST0Hello Yogesh Sharma thanks for writing below links i hope helpful for you......:) http://www.c-sharpcorner.com/UploadFile/81a718/3-simple-steps-to-create-your-first-Asp-Net-web-api-service/ https://code.msdn.microsoft.com/ASPNET-Web-API-JavaScript-d0d64dd7 http://www.dotnet-tricks.com/Tutorial/webapi/E3K8220314-Securing-ASP.NET-Web-API-using-basic-Authentication.html 0Yogesh Sharma123 reputation10y agoPosted Feb 25, 2016, 12:51 AM EST0Dear Amit Kumar, Can you explain with gui....because its my first api0Yogesh Sharma123 reputation10y agoPosted Feb 25, 2016, 12:58 AM EST0i tired since last three days.. no any solutions found so, please help me...0Amit Kumar SinghRank #562 · 4.3K reputation10y agoPosted Feb 25, 2016, 1:01 AM EST0u want to create asp.net application through database...i am rit0Amit KumarRank #459 · 5.4K reputation10y agoPosted Feb 25, 2016, 1:10 AM EST0Hi dear, U want to do it in Asp.net or MVC. 0Krishna Rajput SinghRank #605 · 4K reputation10y agoPosted Feb 25, 2016, 1:15 AM EST0use my links0Yogesh Sharma123 reputation10y agoPosted Feb 25, 2016, 1:25 AM EST0asp.net0Yogesh Sharma123 reputation10y agoPosted Feb 25, 2016, 1:26 AM EST0yes0Amit Kumar SinghRank #562 · 4.3K reputation10y agoPosted Feb 25, 2016, 1:28 AM EST0http://www.c-sharpcorner.com/UploadFile/0c1bb2/login-page-in-Asp-Net-C-Sharp-web-application-using-stored-proce/0Yogesh Sharma123 reputation10y agoPosted Feb 25, 2016, 1:32 AM EST0Thanks for your reply... But your article is about login with sp... but i want api not sp or query....0Yogesh Sharma123 reputation10y agoPosted Feb 25, 2016, 3:35 AM EST0Thanks to all of you ............ So finally i have created Login API... See as below : This is My Model : using System;using System.Collections.Generic;using System.Linq;using System.Web;namespace API_Demo.Models{ public class LoginModel { public string Acc_Email_ID { get; set; } public string Password { get; set; } }} This is my controller : using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using API_Demo.Models;namespace API_Demo.Controllers{ public class HomeController : Controller { public ActionResult Index() { LoginModel obj = new LoginModel(); return View(obj); //For bind the view } [HttpPost] public ActionResult Index(LoginModel objuserlogin) { var display = Userloginvalues().Where(m => m.Acc_Email_ID == objuserlogin.Acc_Email_ID && m.Password == objuserlogin.Password).FirstOrDefault(); if (display != null) { ViewBag.Status = "CORRECT UserNAme and Password"; } else { ViewBag.Status = "INCORRECT UserName or Password"; } return View(objuserlogin); } public List Userloginvalues() { List objModel = new List(); objModel.Add(new LoginModel { Acc_Email_ID = "user1", Password = "password1" }); return objModel; } }} This is my view : @model API_Demo.Models.LoginModel@{ ViewBag.Title = "Index";} function display() { if ($("#txtusername").attr("value") == "") { alert("Please Enter your UserName."); return false; } else if ($("#txtuserpassword").attr("value") == "") { alert("Please enter UserPassword."); return false; } alert("Login Successfully"); return true; }Simple We API Login Form @using (Html.BeginForm("Index", "Home")){@ViewBag.Status User Name : @Html.TextBoxFor(m => m.Acc_Email_ID, new { @style = "width:200px", @id = "txtusername" }) User Password : @Html.PasswordFor(m => m.Password, new { @style = "width:200px", @id = "txtuserpassword" }) } So, in this API i have checked the id and password offline... (i.e. already defined)... But, i want check userid and password from sql table ... So, please suggest me how to check from sql table.... 0Yogesh Sharma123 reputation10y agoPosted Feb 25, 2016, 8:41 PM EST0can you explain me how to data table check it ???0Join to answer this questionEvery answer you publish earns 20 SHARP.Create free accountSign inKnow the answer?Answer a question in the forums and earn +20 SHARP for every answer.See unanswered questionsForumsTop experts01Arun PottiAnswers in the forums20answers02Tahir AnsariAnswers in the forums5answers03Kamlesh KumarAnswers in the forums5answers04Sam HobbsAnswers in the forums4answers05Željko PerićAnswers in the forums3answers?YouYour name goes here.Every answer: 20 SHARP.JoinFull leaderboard →2026DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Yogesh Sharma123 reputation10y agoPosted Feb 25, 2016, 12:03 AM EST0Thanks for your quick reply.... But, i want to check userid and password from sql table... 0
Amit KumarRank #459 · 5.4K reputation10y agoPosted Feb 25, 2016, 12:13 AM EST0Ok , Check it my above Post again ... I have use database for login... 0
Amit Kumar SinghRank #562 · 4.3K reputation10y agoPosted Feb 25, 2016, 12:15 AM EST0IF EXISTS(SELECT USERID,PASSWORD FROM EMPLOYEE WHERE USERID=@USERID AND PASSWORD=@PASSWORD) BEGIN SELECT 'LOGIN WAS SUCCESSFULLY' ENDELSE BEGIN SELECT 'USERID AND PASSWORD WAS INCORRECT' END0
Krishna Rajput SinghRank #605 · 4K reputation10y agoPosted Feb 25, 2016, 12:34 AM EST0Hello Yogesh Sharma thanks for writing below links i hope helpful for you......:) http://www.c-sharpcorner.com/UploadFile/81a718/3-simple-steps-to-create-your-first-Asp-Net-web-api-service/ https://code.msdn.microsoft.com/ASPNET-Web-API-JavaScript-d0d64dd7 http://www.dotnet-tricks.com/Tutorial/webapi/E3K8220314-Securing-ASP.NET-Web-API-using-basic-Authentication.html 0
Yogesh Sharma123 reputation10y agoPosted Feb 25, 2016, 12:51 AM EST0Dear Amit Kumar, Can you explain with gui....because its my first api0
Yogesh Sharma123 reputation10y agoPosted Feb 25, 2016, 12:58 AM EST0i tired since last three days.. no any solutions found so, please help me...0
Amit Kumar SinghRank #562 · 4.3K reputation10y agoPosted Feb 25, 2016, 1:01 AM EST0u want to create asp.net application through database...i am rit0
Amit KumarRank #459 · 5.4K reputation10y agoPosted Feb 25, 2016, 1:10 AM EST0Hi dear, U want to do it in Asp.net or MVC. 0
Amit Kumar SinghRank #562 · 4.3K reputation10y agoPosted Feb 25, 2016, 1:28 AM EST0http://www.c-sharpcorner.com/UploadFile/0c1bb2/login-page-in-Asp-Net-C-Sharp-web-application-using-stored-proce/0
Yogesh Sharma123 reputation10y agoPosted Feb 25, 2016, 1:32 AM EST0Thanks for your reply... But your article is about login with sp... but i want api not sp or query....0
Yogesh Sharma123 reputation10y agoPosted Feb 25, 2016, 3:35 AM EST0Thanks to all of you ............ So finally i have created Login API... See as below : This is My Model : using System;using System.Collections.Generic;using System.Linq;using System.Web;namespace API_Demo.Models{ public class LoginModel { public string Acc_Email_ID { get; set; } public string Password { get; set; } }} This is my controller : using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using API_Demo.Models;namespace API_Demo.Controllers{ public class HomeController : Controller { public ActionResult Index() { LoginModel obj = new LoginModel(); return View(obj); //For bind the view } [HttpPost] public ActionResult Index(LoginModel objuserlogin) { var display = Userloginvalues().Where(m => m.Acc_Email_ID == objuserlogin.Acc_Email_ID && m.Password == objuserlogin.Password).FirstOrDefault(); if (display != null) { ViewBag.Status = "CORRECT UserNAme and Password"; } else { ViewBag.Status = "INCORRECT UserName or Password"; } return View(objuserlogin); } public List Userloginvalues() { List objModel = new List(); objModel.Add(new LoginModel { Acc_Email_ID = "user1", Password = "password1" }); return objModel; } }} This is my view : @model API_Demo.Models.LoginModel@{ ViewBag.Title = "Index";} function display() { if ($("#txtusername").attr("value") == "") { alert("Please Enter your UserName."); return false; } else if ($("#txtuserpassword").attr("value") == "") { alert("Please enter UserPassword."); return false; } alert("Login Successfully"); return true; }Simple We API Login Form @using (Html.BeginForm("Index", "Home")){@ViewBag.Status User Name : @Html.TextBoxFor(m => m.Acc_Email_ID, new { @style = "width:200px", @id = "txtusername" }) User Password : @Html.PasswordFor(m => m.Password, new { @style = "width:200px", @id = "txtuserpassword" }) } So, in this API i have checked the id and password offline... (i.e. already defined)... But, i want check userid and password from sql table ... So, please suggest me how to check from sql table.... 0Yogesh Sharma123 reputation10y agoPosted Feb 25, 2016, 8:41 PM EST0can you explain me how to data table check it ???0Join to answer this questionEvery answer you publish earns 20 SHARP.Create free accountSign inKnow the answer?Answer a question in the forums and earn +20 SHARP for every answer.See unanswered questionsForumsTop experts01Arun PottiAnswers in the forums20answers02Tahir AnsariAnswers in the forums5answers03Kamlesh KumarAnswers in the forums5answers04Sam HobbsAnswers in the forums4answers05Željko PerićAnswers in the forums3answers?YouYour name goes here.Every answer: 20 SHARP.JoinFull leaderboard →2026DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Yogesh Sharma123 reputation10y agoPosted Feb 25, 2016, 8:41 PM EST0can you explain me how to data table check it ???0
Amit Kumar SinghRank #562 · 4.3K reputationPosted Feb 25, 2016, 1:36 AM EST
Amit KumarRank #459 · 5.4K reputationPosted Feb 24, 2016, 11:59 PM EST
Yogesh Sharma123 reputationPosted Feb 25, 2016, 12:03 AM EST
Amit KumarRank #459 · 5.4K reputationPosted Feb 25, 2016, 12:13 AM EST
Amit Kumar SinghRank #562 · 4.3K reputationPosted Feb 25, 2016, 12:15 AM EST
Krishna Rajput SinghRank #605 · 4K reputationPosted Feb 25, 2016, 12:34 AM EST
Yogesh Sharma123 reputationPosted Feb 25, 2016, 12:51 AM EST
Yogesh Sharma123 reputationPosted Feb 25, 2016, 12:58 AM EST
Amit Kumar SinghRank #562 · 4.3K reputationPosted Feb 25, 2016, 1:01 AM EST
Amit KumarRank #459 · 5.4K reputationPosted Feb 25, 2016, 1:10 AM EST
Krishna Rajput SinghRank #605 · 4K reputationPosted Feb 25, 2016, 1:15 AM EST
Yogesh Sharma123 reputationPosted Feb 25, 2016, 1:25 AM EST
Yogesh Sharma123 reputationPosted Feb 25, 2016, 1:26 AM EST
Amit Kumar SinghRank #562 · 4.3K reputationPosted Feb 25, 2016, 1:28 AM EST
Yogesh Sharma123 reputationPosted Feb 25, 2016, 1:32 AM EST
Yogesh Sharma123 reputationPosted Feb 25, 2016, 3:35 AM EST
Simple We API Login Form
Yogesh Sharma123 reputationPosted Feb 25, 2016, 8:41 PM EST
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts