public void TestPasswordVerifyWithGoodPassword() { CryptoPassword crypto = new CryptoPassword(); string clearPassword = "******"; string encryptedPassword = crypto.Hash(clearPassword); bool verify = crypto.Verify(clearPassword, encryptedPassword); Assert.AreEqual(true, verify); }
public void TestPasswordVerifyWithWrongPassword() { CryptoPassword crypto = new CryptoPassword(); string actualPassword = "******"; string wrongPassword = "******"; string encryptedPassword = crypto.Hash(actualPassword); bool verify = crypto.Verify(wrongPassword, encryptedPassword); Assert.AreEqual(false, verify); }
/// <summary> /// Check if the username and the password of the user is correct /// </summary> /// <param name="login"></param> /// <returns>True if OK</returns> /// <returns>Exception if not OK</returns> public bool LoginDb(Login login) { CheckData loginCheck = new CheckData(); DbConnection connection = new DbConnection(); CryptoPassword c = new CryptoPassword(); //Check if the fields aren't empty loginCheck.CheckLoginField(login.userEmail, login.password); //Check if the userEmail exist in the database if (!connection.CheckEmail(userEmail)) { return(false); } //Get the password form the database from the validated userEmail var hashedPassword = connection.GetUserPassword(userEmail); //Return true or false if the input password match or not the database password return(c.Verify(password, hashedPassword)); }