public async Task <UserDTO> RegisterAsync(string userName, string password)
        {
            //keep this code for future references
            using var hmac = new HMACSHA512();

            var user = new AppUser
            {
                Name         = userName.ToLower(),
                PasswordHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(password)),
                PasswordSalt = hmac.Key
            };

            _context.Users.Add(user);
            await _context.SaveChangesAsync();

            return(new UserDTO
            {
                UserName = user.Name,
                Token = _tokenService.CreateToken(user),
            });
        }
Ejemplo n.º 2
0
        public async Task AddUserAsync(AppUser user)
        {
            await _context.Users.AddAsync(user);

            await _context.SaveChangesAsync();
        }