/// <summary> /// Test if the login and the password correspond to a user in the database /// </summary> /// <param name="user"></param> /// <returns></returns> public bool ValiderFunction(ref User user) { try { if (user.login == "" || user.password == "") { throw new Exception("Login or Password is empty"); } if (!RegexFunction.isValidstring(user.login, 1, 40)) { throw new Exception("Login doesn't correspond to the standard"); } if (!RegexFunction.isValidPassword(user.password)) { throw new Exception("Password doesn't correspond to the standard"); } BDD mybdd = new BDD(); User userTest = new User(); if (mybdd.getUser(user.login, ref userTest) != 1) { throw new Exception("Login doesn't exist in the database"); } string hashedPassword = user.password; user = userTest; return(BCrypt.Net.BCrypt.Verify(hashedPassword, user.password)); } catch { return(false); } }
private void btRegister_Click(object sender, RoutedEventArgs e) { try { //test des différents champs if (!RegexFunction.isValidstring(tbLogin.Text, 1, 30)) { throw new Exception("Login invalid"); } if (!RegexFunction.isValidPassword(passwordBox1.Password) && passwordBox1.Password == passwordBox2.Password) { throw new Exception("Password invalid"); } if (!RegexFunction.isValidstring(tbFirstName.Text, 1, 40)) { throw new Exception("FirstName invalid"); } if (!RegexFunction.isValidstring(tbLastName.Text, 1, 40)) { throw new Exception("LastName invalid"); } if (!RegexFunction.isValidEmail(tbEmail.Text)) { throw new Exception("Email invalid"); } //verification du login BDD mybdd = new BDD(); User user = new User(); if (mybdd.getUser(tbLogin.Text, ref user) == 1) { throw new Exception("Login already exist in the database"); } string hashedPassword = BCrypt.Net.BCrypt.HashPassword(passwordBox1.Password); user = new User(0, tbFirstName.Text, tbLastName.Text, tbEmail.Text, hashedPassword, tbLogin.Text); mybdd.addUser(user); this.Close(); } catch (Exception ex) { lblErrorMsg.Content = ex.Message; } }