protected void btnLogIn_Click(object sender, EventArgs e) { Games_Arena_DB_Context dbContext = new Games_Arena_DB_Context(); User user = dbContext.Users.FirstOrDefault(x => x.Email_Address == txtLIUserName.Text); if (user != null) { if (user.LockedDateTime <= DateTime.Now) { UnlockedTheUser(user); } if (user.IsLocked == false) { if (user.Password == EncryptedPassword(txtLIPassword.Text)) { UnlockedTheUser(user); //Authenticate User and redirect to admin Page FormsAuthentication.RedirectFromLoginPage(user.Email_Address, false); ErrorMessageLogIn("Welcome", true); } else { if (user.Retry_Attempts == 3) { user.IsLocked = true; user.Retry_Attempts = 0; user.LockedDateTime = DateTime.Now.AddMinutes(1); ErrorMessageLogIn("You have been locked by Admin till " + user.LockedDateTime, true); } else { ErrorMessageLogIn("Password Doesn't Match You have left (0" + (3 - user.Retry_Attempts) + ") Attempt(s)", true); } user.Retry_Attempts += 1; } } else { ErrorMessageLogIn("You have been locked by Admin till " + user.LockedDateTime, true); } } else { ErrorMessageLogIn("User Name / Password Doesn't Match", true); } dbContext.SaveChanges(); }
protected void btnFPVerify_Click(object sender, EventArgs e) { Games_Arena_DB_Context dbContext = new Games_Arena_DB_Context(); User user = dbContext.Users.FirstOrDefault(x => x.Email_Address == txtFPUserName.Text); if (user != null) { if (user.LockedDateTime <= DateTime.Now) { UnlockedTheUser(user); } if (user.IsLocked == false) { if (ddlFPSecretQuestion.SelectedValue == "Select Option") { //SendRestPasswordEmails(user.Gmail, user.First_Name + " " + user.Last_Name, user.) ErrorMessageForgetPassword("The Email has been Sent to your Email Address", true); } else { if (user.Secret_Question == ddlFPSecretQuestion.SelectedValue && user.Secret_Answer == EncryptedPassword(txtFPSecretAnswer.Text)) { Random random = new Random(); int randomNumber = random.Next(DateTime.Now.Second); user.Password = EncryptedPassword(randomNumber + " Pakistan"); ErrorMessageForgetPassword("Your New Password is \"" + randomNumber + " Pakistan\"", true); dbContext.SaveChanges(); } else { ErrorMessageForgetPassword("Email and Secret Question / Answer Doesn't Match", true); } } } else { ErrorMessageForgetPassword("You have been locked by Admin till " + user.LockedDateTime, true); } } else { ErrorMessageForgetPassword("Email and Secret Question / Answer Doesn't Match", true); } }