protected void btnLogin_Click(object sender, EventArgs e) { // Response.Redirect("~/Dashboard/Dashboard.aspx", true); try { Reply response = new Reply(); LoginCred objUserDetailsReq = new LoginCred(); objUserDetailsReq.username = txtUserName.Text; objUserDetailsReq.password = txtPwd.Text; var Jsonstring = JsonConvert.SerializeObject(objUserDetailsReq); WebClient client = new WebClient(); client.Headers[HttpRequestHeader.ContentType] = "Application/json"; string result = client.UploadString(URL + "/checkLogin", "POST", Jsonstring); System.IO.MemoryStream ms = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(result)); DataContractJsonSerializer deserializer = new DataContractJsonSerializer(typeof(Reply)); Reply obj = (Reply)deserializer.ReadObject(ms); if (obj.result) { Session["loginid"] = obj.DS.Tables[0].Rows[0]["idlogin"].ToString(); Session["mail_id"] = obj.DS.Tables[0].Rows[0]["mail_id"].ToString(); Session["Username"] = obj.DS.Tables[0].Rows[0]["user_name"].ToString(); Session["usertype"] = obj.DS.Tables[0].Rows[0]["user_role"].ToString(); string Uname = Session["Username"].ToString(); string uid = Session["loginid"].ToString(); if (obj.DS.Tables[0].Rows[0]["password"].ToString().ToLower().Contains("lipi@123")) { Response.Redirect("Dashboard/updatepassword.aspx?Username="******"&UID=" + Convert.ToBase64String(Encoding.ASCII.GetBytes(uid)), false); } else { Response.Redirect("~/Dashboard/Dashboard.aspx", true); } } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "myScript", "wrongUserNameAndPwd();", true); } } catch (Exception ex) { Log.Write("Exception in Login Error :- " + ex.ToString(), ""); } }
public ActionResult Autherize(LoginCred credModel) { using (GiftsOnlineDBEntities db = new GiftsOnlineDBEntities()) { var check = db.LoginCreds.Where(hs => hs.emailadmin.Equals(credModel.emailadmin)).FirstOrDefault(); var check2 = db.LoginCreds.Where(x => x.passtologin.Equals(credModel.passtologin)).FirstOrDefault(); if (check == null || check2 == null) { credModel.LoginErrorMessage = "Invalid or Empty Credentials!"; return(View("AdminLogin", credModel)); } else { Session["email"] = check.emailadmin; return(RedirectToAction("HomePage", "Home")); } } }
public async Task <IActionResult> LoginAsync([FromBody] LoginCred value, string returnUrl) { //Signout any existing user if one is logged in await HttpContext.SignOutAsync(IdentityConstants.ApplicationScheme); // Log user in var result = await _signInManager.PasswordSignInAsync(value.UserName, value.Password, true, true); if (result.Succeeded) { // If there is no return URL go to home page if (string.IsNullOrEmpty(returnUrl)) { // GO to Home page return(RedirectToAction(nameof(Index))); } // Else return to url inwhich user was redirected to login from return(Redirect(returnUrl)); } return(Content("Failed to login", "text/html")); }
// POST: api/Usuario //[HttpPost] public Usuario Login([FromBody] LoginCred credenciales) { return(context.Usuario.FirstOrDefault(u => u.Email == credenciales.Email && u.Password == credenciales.Password)); }