protected void ButtonCheck_Click(object sender, EventArgs e) { TextBox userName = (TextBox)UserFormView.FindControl("Login"); Service service = new Service(); User user = service.GetUserByLoginID(userName.Text); if (ModelState.IsValid) { try { Session["Reg"] = true; if (user == null || user.LoginID == "") { PlaceHolderCheckOK.Visible = true; } else { PlaceHolderCheckFail.Visible = true; } } catch (Exception) { ModelState.AddModelError(String.Empty, "Fel inträffade."); } } }
public void UserFormView_InsertItem(WebshopClick.Model.BLL.User user) { //Checks if username already exists in the database TextBox userName = (TextBox)UserFormView.FindControl("Login"); Service service = new Service(); User checkUser = service.GetUserByLoginID(userName.Text); if (checkUser != null) { Session["Reg"] = true; PlaceHolderCheckFail.Visible = true; return; } //Salting password before hashing TextBox pswOriginal = (TextBox)UserFormView.FindControl("Password"); pswOriginal.Text = pswOriginal.Text + userName.Text; TextBox pswConfirm = (TextBox)UserFormView.FindControl("ConfirmPassword"); pswConfirm.Text = pswConfirm.Text + userName.Text; //Hashing of password string hash1 = PasswordHasher.Hash(pswOriginal.Text); string hash2 = PasswordHasher.Hash(pswConfirm.Text); if (ModelState.IsValid) { try { user.Password = hash1; service.UpdateUser(user); FlashPlaceHolder.Visible = true; isLoged(); } catch (Exception) { ModelState.AddModelError(String.Empty, "Fel inträffade då användare skulle läggas till."); } } }
protected void LoginButton_Click(object sender, EventArgs e) { Service service = new Service(); string pass = PasswordLogin.Text; string userName = UsernameLogin.Text; string password = PasswordLogin.Text + UsernameLogin.Text; string psw = PasswordHasher.Hash(password); User user = service.GetUserByLoginID(userName); if (user != null) { if (user.Password == psw) { Session["User"] = user; isLoged(); return; } } PlaceHolder1.Visible = true; }