示例#1
0
        public void ChangePassword(string oldPassword, string newPassword, IPasswordHashService hashService)
        {
            if (IsValidPassword(newPassword) == false)
                throw new ArgumentException("The password should be between 8 and 20 symbols and it should contain a number, a captial letter and a special symbol.");

            if (hashService.GetPasswordHash(oldPassword) == PasswordHash)
            {
                PasswordHash = hashService.GetPasswordHash(newPassword);
            }
            else
                throw new InvalidOperationException("Wrong passoword");
        }
示例#2
0
        public User(Guid id, string username, string password, IPasswordHashService hashService)
        {
            if (id == default(Guid))
            {
                throw new ArgumentException($"Invalid user id {id}.", nameof(id));
            }

            if (IsValidUsername(username) == false)
            {
                throw new ArgumentException("The username should be alphanumeric, between 6 and 20 symbols, and it could contain '_' or '-'.");
            }

            if (IsValidPassword(password) == false)
            {
                throw new ArgumentException("The password should be between 8 and 20 symbols and it should contain a number, a captial letter and a special symbol.");
            }

            if (hashService == null)
            {
                throw new ArgumentNullException("Hash service is required.", nameof(hashService));
            }

            Id           = id;
            Username     = username;
            PasswordHash = hashService.GetPasswordHash(password);
        }
示例#3
0
        public void ChangePassword(string oldPassword, string newPassword, IPasswordHashService hashService)
        {
            if (IsValidPassword(newPassword) == false)
            {
                throw new ArgumentException("The password should be between 8 and 20 symbols and it should contain a number, a captial letter and a special symbol.");
            }

            if (hashService.GetPasswordHash(oldPassword) == PasswordHash)
            {
                PasswordHash = hashService.GetPasswordHash(newPassword);
            }
            else
            {
                throw new InvalidOperationException("Wrong passoword");
            }
        }
示例#4
0
        public User(Guid id, string username, string password, IPasswordHashService hashService)
        {
            if (id == default(Guid))
                throw new ArgumentException($"Invalid user id {id}.", nameof(id));

            if (IsValidUsername(username) == false)
                throw new ArgumentException("The username should be alphanumeric, between 6 and 20 symbols, and it could contain '_' or '-'.");

            if (IsValidPassword(password) == false)
                throw new ArgumentException("The password should be between 8 and 20 symbols and it should contain a number, a captial letter and a special symbol.");

            if (hashService == null)
                throw new ArgumentNullException("Hash service is required.", nameof(hashService));

            Id = id;
            Username = username;
            PasswordHash = hashService.GetPasswordHash(password);
        }