예제 #1
0
 /// <summary>
 /// hashes the password, then adds the user to the database
 /// </summary>
 /// <param name="user">the user that will be added</param>
 /// <returns>if the user got added</returns>
 public bool AddUser(User user)
 {
     if (user.Password.Length > 5)
     {
         byte[] passwordByte = Encoding.UTF8.GetBytes(user.Password);
         byte[] salt         = hashing.GenerateSalt(32);
         user.Password = Convert.ToBase64String(hashing.ComputeMAC(passwordByte, salt));
         user.Salt     = Convert.ToBase64String(salt);
         return(dataManager.AddUser(user));
     }
     return(false);
 }
 /// <summary>
 /// hashes the password, then adds the user to the database
 /// </summary>
 /// <param name="username">the username of the user</param>
 /// <param name="password">the password of the user</param>
 /// <returns></returns>
 public bool AddUser(string username, string password)
 {
     if (password.Length > 5)
     {
         byte[] passwordByte = Encoding.UTF8.GetBytes(password);
         byte[] salt = hashing.GenerateSalt(32);
         password = Convert.ToBase64String(hashing.ComputeMAC(passwordByte, salt));
         User user = new User();
         user.Password = password;
         user.Username = username;
         user.Salt = Convert.ToBase64String(salt);
         return dataManager.AddUser(user);
     }
     return false;
 }
예제 #3
0
        public async Task <Result <Guid> > Handle(TenantCreateCommand request, CancellationToken cancellationToken)
        {
            var isTenantDuplicating = await _repository.AnyAsync(x => x.Logon.Equals(request.Logon), cancellationToken);

            if (isTenantDuplicating)
            {
                return(Result.Failure <Guid>(ErrorType.Duplicating.ToString()));
            }

            var tenant = _mapper.Map <Tenant>(request);

            tenant.Salt     = _hashing.GenerateSalt();
            tenant.Password = _hashing.GenerateHash(request.Password, tenant.Salt);

            var createdTenant = await _repository.CreateAsync(tenant, cancellationToken);

            return(await CommitAsync() > 0
                ? createdTenant.ID
                : Result.Failure <Guid>(ErrorType.SaveChangesFailure.ToString()));
        }