Beispiel #1
0
        private static bool CheckPassword(User user, string password)
        {
            var hash    = SHA512Helper.GetHash(password);
            var isValid = user.PasswordHash == hash;

            return(isValid);
        }
Beispiel #2
0
        /// <summary>
        /// Создать пользователя
        /// </summary>
        public async Task CreateAsync(User user, string password, CancellationToken cancellationToken = default(CancellationToken))
        {
            user     = user ?? throw new ArgumentNullException(nameof(user));
            password = password ?? throw new ArgumentNullException(nameof(password));

            user.PasswordHash = SHA512Helper.GetHash(password);
            await _appDbContext.AddAsync(user, cancellationToken);

            await _appDbContext.SaveChangesAsync(cancellationToken);
        }
Beispiel #3
0
        public void CheckPassword_Positive()
        {
            const string password = "******";

            IUserManager userManager = new UserManager(_mockDbContext.Object);
            var          user        = new User {
                PasswordHash = SHA512Helper.GetHash(password)
            };
            var isValid = userManager.CheckPassword(user, password);

            Assert.True(isValid);
        }
Beispiel #4
0
        public void CheckPassword_Negative()
        {
            const string password1 = "123";
            const string password2 = "111";

            IUserManager userManager = new UserManager(_mockDbContext.Object);
            var          user        = new User {
                PasswordHash = SHA512Helper.GetHash(password1)
            };
            var isValid = userManager.CheckPassword(user, password2);

            Assert.False(isValid);
        }