public void CanHashValues() { var pass1 = "FeKI*9IZlcQ2Bk$;EEUx"; var salt1 = "7wEPvh7KFgIX3B1vo1McOPYhkVLUQipLnwZuHEL2l5hAwfGVDjHPTFCtuNVqh33qFfrdboxqidBTKZWtlaJuTSIrS6vvVz7fRktdracm0Q1WBDFNuRnwStmgbYv7bZcV"; var saltedHasher = new Sha256SaltedHasher(); var hash1 = saltedHasher.GetHashBytesString(pass1, salt1); var hash2 = saltedHasher.GetHashBytesString(pass1, salt1); Assert.NotEmpty(hash1); Assert.Equal(hash1, hash2); }
private Maybe <UserInfo> GetUser(string login, string pass) { if (string.IsNullOrWhiteSpace(login)) { Maybe <UserInfo> .NewFailure($"{nameof(login)} is NULL / Empty / Whitespace."); } if (string.IsNullOrWhiteSpace(pass)) { Maybe <UserInfo> .NewFailure($"{nameof(pass)} is NULL / Empty / Whitespace."); } var maybeUser = _userInfoService.GetUserInfo(login: login); if (maybeUser.Success) { var user = maybeUser.Value; var currentHash = _saltedHasher.GetHashBytesString(pass, user.PassSalt); var userIsTheSame = currentHash.Equals(user.PassHash, StringComparison.OrdinalIgnoreCase); if (userIsTheSame) { return(maybeUser); } } return(Maybe <UserInfo> .NewFailure("Can't find user by provided credentials.")); }