Esempio n. 1
0
        public async Task <IUserModel> VerifyUserAsync(IUserLoginModel model)
        {
            try
            {
                var userInfo = await _db.Users.Where(u => u.Username == model.Username).SingleOrDefaultAsync();

                if (userInfo != null)
                {
                    var salt         = Convert.FromBase64String(userInfo.Salt);
                    var hashPassword = Convert.FromBase64String(userInfo.Password);
                    var isVerified   = PasswordHash.VerifyPassword(model.Password, salt, hashPassword);

                    if (!isVerified)
                    {
                        return(null);
                    }
                    else
                    {
                        return(new UserModel
                        {
                            UserId = userInfo.Id,
                            Name = userInfo.Name
                        });
                    }
                }

                return(null);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        public void Login(IUserLoginModel userToLogin)
        {
            if (this.LoggedUser != null)
            {
                throw new ArgumentException("User already logged in!");
            }

            this.LoggedUser = userToLogin ?? throw new ArgumentNullException(nameof(userToLogin));
        }
Esempio n. 3
0
 public async Task <IUserModel> VerifyUserAsync(IUserLoginModel model) => await _userRepo.VerifyUserAsync(model);
 public void Logout()
 {
     this.LoggedUser = null;
 }