Exemplo n.º 1
0
        private Model.User CreateUser(Input.User userDto)
        {
            var salt     = CreateSalt();
            var password = GenerateHash(userDto.Password, salt);
            var user     = new Model.User
            {
                Username           = userDto.Username,
                PasswordHash       = password,
                PasswordEncryption = "SHA256",
                PasswordSalt       = salt
            };

            return(user);
        }
Exemplo n.º 2
0
        public IActionResult Login([FromBody] Input.User userDto)
        {
            var user = userRepository.Get().FirstOrDefault(u => u.Username == userDto.Username);

            if (user == null)
            {
                return(NotFound());
            }

            var password = GenerateHash(userDto.Password, user.PasswordSalt);

            if (password == user.PasswordHash)
            {
                return(Ok(user.Id));
            }
            else
            {
                return(Unauthorized());
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Register([FromBody] Input.User userDto)
        {
            var userId = await userRepository.Insert(CreateUser(userDto));

            return(Ok(userId));
        }