Esempio n. 1
0
        public User CreateUser(string userName, string password, string userRole)
        {
            ValidateUser(userName, password, userRole);
            byte[] generatedSalt = AuthenticationHelper.GenerateSalt();

            return(new User
            {
                Username = userName,
                Salt = generatedSalt,
                Password = AuthenticationHelper.GenerateHash(password, generatedSalt),
                UserRole = userRole
            });
        }
Esempio n. 2
0
        public User CreateUser(string userName, string password, string userRole)
        {
            int minPasswordLenght = 5;

            if (string.IsNullOrEmpty(userName))
            {
                throw new ArgumentException("Entered username too short");
            }
            if (string.IsNullOrEmpty(password) || password.Length < minPasswordLenght)
            {
                throw new ArgumentException("Entered password too short");
            }
            if (string.IsNullOrEmpty(userRole))
            {
                throw new ArgumentException("Entered user role too short");
            }

            byte[] generatedSalt = AuthenticationHelper.GenerateSalt();

            return(new User
            {
                Username = userName,
                Salt = generatedSalt,
                Password = AuthenticationHelper.GenerateHash(password, generatedSalt),
                UserRole = userRole
            });
        }