Пример #1
0
        public async Task <UserDTO> SignupUserAsync(SignUpPayload payload, CancellationToken ct = default)
        {
            var count = await _users.CountDocumentsAsync(user => user.Email !.Equals(payload.Email), null, ct);

            if (count > 0)
            {
                throw new ArgumentException("User Already Exists");
            }
            var password = BCryptNet.EnhancedHashPassword(payload.Password);
            var user     = new User
            {
                Email    = payload.Email,
                LastName = payload.LastName,
                Name     = payload.Name,
                Password = password
            };
            await _users.InsertOneAsync(user, null, ct);

            var newUser = await _users.FindAsync(user => user.Email == payload.Email, null, ct);

            var firstuser = newUser.FirstOrDefault(ct);

            return(new UserDTO
            {
                Email = firstuser.Email,
                LastName = firstuser.LastName,
                Name = firstuser.Name,
                Id = firstuser.Id
            });
        }
Пример #2
0
        public HashResult GetHash(string plainText)
        {
            var salt          = _secureRandomGenerator.RandomString(32);
            var saltedText    = salt + plainText;
            var encryptedText = _encryptionService.Encrypt(saltedText);
            var hash          = BCryptHasher.EnhancedHashPassword(encryptedText);

            return(new HashResult(hash, salt));
        }
Пример #3
0
 public static string Encrypt(string password)
 {
     return(Crypt.EnhancedHashPassword(password));
 }
Пример #4
0
 public static string Hash(string password)
 {
     return(BCr.EnhancedHashPassword(password));
     //return BCr.HashPassword(pass, enhancedEntropy: true);
 }