Check Password and Username Login in MVC

Code :


       [Route("Login")]
        public ActionResult Login()
        {
            
            return View();
        }

        [Route("Login")]
        [HttpPost]

        public ActionResult Login(MyLogin md)
        {
            Session["username"] = md.ToString();
            Session["password"] = md.ToString();
            FormDbEntities db = new FormDbEntities();
            var data= db.tbl_Login.Where(x => x.Userid == md.Userid && x.password == md.password).Count();
            if(data>0)
            {
                
               return RedirectToAction("Home");
                

            }
            else
            {
                return View();
            }
            
        }





HtmlCS File Code :

@model Test.Models.tbl_Login

<h2 id="loginhead">Login</h2><h3>@Session["data"]</h3><div class="container mainlog">    @using (Html.BeginForm())    {        @Html.AntiForgeryToken()        <div class="form-horizontal" id="Log">            <hr />            @Html.ValidationSummary(true, "", new { @class = "text-danger" })            <div class="form-group">                @Html.LabelFor(model => model.Userid, htmlAttributes: new { @class = "control-label col-md-2 " })                <div class="col-md-10">                    @Html.EditorFor(model => model.Userid, new { htmlAttributes = new { @class = "form-control" } })                    @Html.ValidationMessageFor(model => model.Userid, "", new { @class = "text-warning" })                </div>            </div>            <div class="form-group">                @Html.LabelFor(model => model.password, htmlAttributes: new { @class = "control-label col-md-2" })                <div class="col-md-10">                    @Html.EditorFor(model => model.password, new { htmlAttributes = new { @class = "form-control" } })                    @Html.ValidationMessageFor(model => model.password, "", new { @class = "text-warning" })                </div>            </div>
            <div class="form-group">                <div class="col-md-offset-2 col-md-10 btnlog">                    <input type="submit" value="Login" class="btn btn-success btn-" />                </div>            </div>        </div>    }</div><link href="~/Content/Login.css" rel="stylesheet" />

Comments

Popular posts from this blog

Search Record From Table Using jQuery in Asp.net core MVC

How To insert Radio Button Data in DataBase -- MVC

Toolbox Webparts Controls