Dear all friends,
The following API check userid and passwords that are already defined...
But, i want to check it from sql server table....
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....

Yogesh SharmaPosted Feb 26, 2016, 1:22 AM
Yogesh SharmaPosted Feb 26, 2016, 12:45 AM
Amit Kumar SinghPosted Feb 26, 2016, 12:20 AM