コード例 #1
0
        public async Task <ActionResult <User> > Register(CreateUser newUser)
        {
            if (newUser.Password != newUser.ConfirmPassword)
            {
                return(BadRequest(new ApiError()
                {
                    Error = "[ConfirmPassword] and [Password] must match"
                }));
            }

            var user = _mapper.Map <UserEntity>(newUser);

            user.Password = CredentialsCypher.ToSha256(user.Password);
            var result = await _userRepository.RegisterAsync(user);

            var link = _linker.GetPathByAction(HttpContext, nameof(Login));

            return(Created(link, _mapper.Map <User>(result)));
        }
コード例 #2
0
        public bool IsAuthorized(string candidatePassword)
        {
            var hashedPwd = CredentialsCypher.ToSha256(candidatePassword);

            return(Password == hashedPwd);
        }