Ejemplo n.º 1
0
        public IActionResult Post([FromBody] RegisterRequest value)
        {
            var sel = (from user in context.Passwords
                       where user.Username.ToUpper() == value.Username.ToUpper()
                       select user).ToList();

            if (sel.Count != 0)
            {
                return(BadRequest(new { error = "Account with given login already exists" }));
            }

            var salt = new byte[4];

            using (var rng = RandomNumberGenerator.Create())
            {
                rng.GetBytes(salt);
            }

            var passHash = hasher.ComputeHash(value.Password, salt);

            context.AddAccount(value.Username, passHash.Value, salt);

            return(Ok(new { answer = "Account created" }));
        }