protected void btnLogin_Click(object sender, EventArgs e) { if (Page.IsValid) { try { UserRepository repositoryUser = new UserRepository(); if (repositoryUser.getUserByCredential(txf_Email.Text.Trim(), FormsAuthentication.HashPasswordForStoringInConfigFile(txf_Password.Text.Trim(), "SHA1")) != null) { // Success, create non-persistent authentication cookie. SecurityLogin.getFormAuthicationToken(txf_Email.Text.Trim()); // 4. Do the redirect. Response.Redirect("~/Dashboard.aspx", true); } else { divError.Visible = true; txf_Email.Text = ""; txf_Password.Text = ""; } } catch (Exception ex) { } } }
public async Task <IActionResult> Create(SecurityLogin securityLogin) { if (ModelState.IsValid) { var config = new MapperConfiguration(cfg => cfg.CreateMap <SecurityLogin, SecurityLoginPoco>()); var mapper = config.CreateMapper(); SecurityLoginPoco poco = mapper.Map <SecurityLoginPoco>(securityLogin); poco.Id = Guid.NewGuid(); _context.Add(poco); await _context.SaveChangesAsync(); TempData["Login"] = poco.Id; return(RedirectToAction("CreateProfile", "ApplicantProfile", new { id = poco.Id })); } return(View(securityLogin)); }
public async Task <IActionResult> VerifyToken(Users users) { SecurityLogin _tokenProvider = new SecurityLogin(); //Authenticate user var userToken = _tokenProvider.LoginUser(users.Username.Trim(), users.Password.Trim()); if (userToken != null) { //Save token in session object HttpContext.Session.SetString("JWToken", userToken); return(Ok()); } else { return(Unauthorized()); } }
public ActionResult Login(SecurityLogin pLogin) { SecurityEF.BLL.SecurityLoginBLL o = new SecurityLoginBLL(); SecurityLogin vLogin = o.GetByLoginName(pLogin.LoginName); if (vLogin == null) { pLogin.Password = string.Empty; ViewBag.LoginError = "The user name or password provided is incorrect...!"; return(View(pLogin)); } else if (pLogin.Password != vLogin.Password) { pLogin.Password = string.Empty; ViewBag.LoginError = "The password provided is incorrect...!"; return(View(pLogin)); } vLogin.Password = string.Empty; string userData = Newtonsoft.Json.JsonConvert.SerializeObject(vLogin); FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, vLogin.LoginName, DateTime.Now, DateTime.Now.AddMinutes(15), false, userData); string encTicket = FormsAuthentication.Encrypt(authTicket); HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket); Response.Cookies.Add(faCookie); return(RedirectToAction("Index", "User")); //if (vLogin.Roles.Split(new char[] { ';' }).Contains("Admin")) //{ // return RedirectToAction("Index", "Home"); //} //else //{ //} }
protected void btnSignUp_Click(object sender, EventArgs e) { try { if (Page.IsValid) { UserRepository repositoryUser = new UserRepository(); repositoryUser.createUser(txfEmail.Text.Trim(), FormsAuthentication.HashPasswordForStoringInConfigFile(txfPassword.Text.Trim(), "SHA1"), txfNameFirst.Text.Trim(), txfNameLast.Text.Trim()); SecurityLogin.getFormAuthicationToken(txfEmail.Text.Trim()); Response.Redirect("~/Dashboard.aspx"); } else { } } catch (Exception ex) { } }
public CustomPrincipal(string Username, SecurityLogin pLogin) { this.Identity = new System.Security.Principal.GenericIdentity(pLogin.LoginName, "Forms"); this.LoginInfo = pLogin; }