Exemplo n.º 1
0
        public static void PopulatePasswordHashes(this IUserAuth newUser, string password, IUserAuth existingUser = null)
        {
            if (newUser == null)
            {
                throw new ArgumentNullException(nameof(newUser));
            }

            var hash = existingUser?.PasswordHash;
            var salt = existingUser?.Salt;

            if (password != null)
            {
                var passwordHasher = !HostContext.Config.UseSaltedHash
                    ? HostContext.TryResolve <IPasswordHasher>()
                    : null;

                if (passwordHasher != null)
                {
                    salt = null; // IPasswordHasher stores its Salt in PasswordHash
                    hash = passwordHasher.HashPassword(password);
                }
                else
                {
                    var hashProvider = HostContext.Resolve <IHashProvider>();
                    hashProvider.GetHashAndSaltString(password, out hash, out salt);
                }
            }

            newUser.PasswordHash = hash;
            newUser.Salt         = salt;

            newUser.PopulateDigestAuthHash(password, existingUser);
        }
Exemplo n.º 2
0
        public static void PopulatePasswordHashes(this IUserAuth newUser, string password, IUserAuth existingUser = null)
        {
            if (newUser == null)
            {
                throw new ArgumentNullException(nameof(newUser));
            }

            var hash = existingUser?.PasswordHash;
            var salt = existingUser?.Salt;

            if (password != null)
            {
                var hashProvider = HostContext.Resolve <IHashProvider>();
                hashProvider.GetHashAndSaltString(password, out hash, out salt);
            }

            newUser.PasswordHash = hash;
            newUser.Salt         = salt;

            newUser.PopulateDigestAuthHash(password, existingUser);
        }