Exemple #1
0
        public async Task <ShortUser> Authenticate(string nickname, string password)
        {
            var user = await Task.Run(() => _wargameContext.User.SingleOrDefault(x => x.Nickname == nickname && x.Password == GenericService.EncryptText(password, "SHA1")));

            // return null if user not found
            if (user == null)
            {
                return(null);
            }

            ShortUser returnedUser = new ShortUser()
            {
                Id       = user.Id,
                Nickname = user.Nickname,
                Email    = user.Email,
            };

            returnedUser.Token = GenerateJSONWebToken(user);

            // authentication successful so return user details without password
            return(returnedUser.WithoutPassword());
        }