public IUserAuth CreateUserAuth(IUserAuth newUser, string password) { ValidateNewUser(newUser, password); AssertNoExistingUser(newUser); var saltedHash = new SaltedHash(); string salt; string hash; saltedHash.GetHashAndSaltString(password, out hash, out salt); var digestHelper = new DigestAuthFunctions(); newUser.DigestHa1Hash = digestHelper.CreateHa1(newUser.UserName, DigestAuthProvider.Realm, password); newUser.PasswordHash = hash; newUser.Salt = salt; newUser.CreatedDate = DateTime.UtcNow; newUser.ModifiedDate = newUser.CreatedDate; using (var session = _documentStore.OpenSession()) { session.Store(newUser); session.SaveChanges(); } return newUser; }
public virtual UserAuth CreateUserAuth(UserAuth newUser, string password) { ValidateNewUser(newUser, password); using (var redis = factory.GetClient()) { AssertNoExistingUser(redis, newUser); var saltedHash = new SaltedHash(); string salt; string hash; saltedHash.GetHashAndSaltString(password, out hash, out salt); newUser.Id = redis.As<UserAuth>().GetNextSequence(); newUser.PasswordHash = hash; newUser.Salt = salt; var digestHelper = new DigestAuthFunctions(); newUser.DigestHA1Hash = digestHelper.CreateHa1(newUser.UserName, DigestAuthProvider.Realm, password); newUser.CreatedDate = DateTime.UtcNow; newUser.ModifiedDate = newUser.CreatedDate; var userId = newUser.Id.ToString(CultureInfo.InvariantCulture); if (!newUser.UserName.IsNullOrEmpty()) redis.SetEntryInHash(IndexUserNameToUserId, newUser.UserName, userId); if (!newUser.Email.IsNullOrEmpty()) redis.SetEntryInHash(IndexEmailToUserId, newUser.Email, userId); redis.Store(newUser); return newUser; } }
public virtual bool TryAuthenticate(string userName, string password, out UserAuth userAuth) { //userId = null; userAuth = GetUserAuthByUserName(userName); if (userAuth == null) return false; var saltedHash = new SaltedHash(); if (saltedHash.VerifyHashString(password, userAuth.PasswordHash, userAuth.Salt)) { return true; } userAuth = null; return false; }
public UserAuth UpdateUserAuth(UserAuth existingUser, UserAuth newUser, string password) { ValidateNewUser(newUser, password); using (var redis = factory.GetClient()) { AssertNoExistingUser(redis, newUser, existingUser); if (existingUser.UserName != newUser.UserName && existingUser.UserName != null) { redis.RemoveEntryFromHash(IndexUserNameToUserId, existingUser.UserName); } if (existingUser.Email != newUser.Email && existingUser.Email != null) { redis.RemoveEntryFromHash(IndexEmailToUserId, existingUser.Email); } var hash = existingUser.PasswordHash; var salt = existingUser.Salt; if (password != null) { var saltedHash = new SaltedHash(); saltedHash.GetHashAndSaltString(password, out hash, out salt); } // If either one changes the digest hash has to be recalculated var digestHash = existingUser.DigestHA1Hash; if (password != null || existingUser.UserName != newUser.UserName) { var digestHelper = new DigestAuthFunctions(); digestHash = digestHelper.CreateHa1(newUser.UserName, DigestAuthProvider.Realm, password); } newUser.Id = existingUser.Id; newUser.PasswordHash = hash; newUser.Salt = salt; newUser.CreatedDate = existingUser.CreatedDate; newUser.ModifiedDate = DateTime.UtcNow; var userId = newUser.Id.ToString(CultureInfo.InvariantCulture); if (!newUser.UserName.IsNullOrEmpty()) redis.SetEntryInHash(IndexUserNameToUserId, newUser.UserName, userId); if (!newUser.Email.IsNullOrEmpty()) redis.SetEntryInHash(IndexEmailToUserId, newUser.Email, userId); redis.Store(newUser); return newUser; } }
public bool TryAuthenticate(string userName, string password, out IUserAuth userAuth) { userAuth = GetUserAuthByUserName(userName); if (userAuth == null) return false; var saltedHash = new SaltedHash(); return saltedHash.VerifyHashString(password, userAuth.PasswordHash, userAuth.Salt); }
public IUserAuth UpdateUserAuth(IUserAuth existingUser, IUserAuth newUser, string password) { ValidateNewUser(newUser, password); AssertNoExistingUser(newUser, existingUser); var hash = existingUser.PasswordHash; var salt = existingUser.Salt; if (password != null) { var saltedHash = new SaltedHash(); saltedHash.GetHashAndSaltString(password, out hash, out salt); } newUser.Id = existingUser.Id; newUser.PasswordHash = hash; newUser.Salt = salt; newUser.CreatedDate = existingUser.CreatedDate; newUser.ModifiedDate = DateTime.UtcNow; Session.Save(new UserAuthNHibernate(newUser)); return newUser; }
public IUserAuth CreateUserAuth(IUserAuth newUser, string password) { ValidateNewUser(newUser, password); AssertNoExistingUser(newUser); var saltedHash = new SaltedHash(); string salt; string hash; saltedHash.GetHashAndSaltString(password, out hash, out salt); newUser.PasswordHash = hash; newUser.Salt = salt; newUser.CreatedDate = DateTime.UtcNow; newUser.ModifiedDate = newUser.CreatedDate; Session.Save(new UserAuthNHibernate(newUser)); return newUser; }
public bool TryAuthenticate(string userName, string password, out IUserAuth userAuth) { //userId = null; userAuth = GetUserAuthByUserName(userName); if (userAuth == null) return false; var saltedHash = new SaltedHash(); if (saltedHash.VerifyHashString(password, userAuth.PasswordHash, userAuth.Salt)) { //userId = userAuth.Id.ToString(CultureInfo.InvariantCulture); return true; } userAuth = null; return false; }
public IUserAuth UpdateUserAuth(IUserAuth existingUser, IUserAuth newUser, string password) { ValidateNewUser(newUser, password); AssertNoExistingUser(mongoDatabase, newUser, existingUser); var hash = existingUser.PasswordHash; var salt = existingUser.Salt; if (password != null) { var saltedHash = new SaltedHash(); saltedHash.GetHashAndSaltString(password, out hash, out salt); } // If either one changes the digest hash has to be recalculated var digestHash = existingUser.DigestHa1Hash; if (password != null || existingUser.UserName != newUser.UserName) { var digestHelper = new DigestAuthFunctions(); digestHash = digestHelper.CreateHa1(newUser.UserName, DigestAuthProvider.Realm, password); } newUser.Id = existingUser.Id; newUser.PasswordHash = hash; newUser.Salt = salt; newUser.DigestHa1Hash = digestHash; newUser.CreatedDate = existingUser.CreatedDate; newUser.ModifiedDate = DateTime.UtcNow; SaveUser(newUser); return newUser; }
public IUserAuth CreateUserAuth(IUserAuth newUser, string password) { ValidateNewUser(newUser, password); AssertNoExistingUser(mongoDatabase, newUser); var saltedHash = new SaltedHash(); string salt; string hash; saltedHash.GetHashAndSaltString(password, out hash, out salt); var digestHelper = new DigestAuthFunctions(); newUser.DigestHa1Hash = digestHelper.CreateHa1(newUser.UserName, DigestAuthProvider.Realm, password); newUser.PasswordHash = hash; newUser.Salt = salt; newUser.CreatedDate = DateTime.UtcNow; newUser.ModifiedDate = newUser.CreatedDate; SaveUser(newUser); return newUser; }