/// <summary> /// Retrieves <see cref="ApplicationUser"/> from DB and perform password check for basic login. /// </summary> /// <returns><see cref="BasicAuthenticationResult"/></returns> public async Task <BasicAuthenticationResult> Authenticate(EncryptedBasicLoginModel model) { var user = await _healthyGamerPortalDbContext.ApplicationUsers.FirstOrDefaultAsync( X => X.Email == Rfc7905.DecryptText(model.Email.Length, model.Email.Text)); // check if user exists if (user == null) { return(null); } // check if password is correct if (!VerifyPasswordHash(Convert.FromBase64String(user.Salt), Encoding.UTF8.GetBytes(Rfc7905.DecryptText(model.Password.Length, model.Password.Text)), Convert.FromBase64String(user.Password))) { return(null); } //Retrieve roles from DB BasicAuthenticationResult result = new BasicAuthenticationResult { Name = user.Email, Roles = new string[] { "Sad", "NotSad" } }; // authentication successful return(result); }
/// <summary> /// Retrieves account type from ApplicationUser based on matching username. /// </summary> /// <returns><see cref="AccountType"/></returns> public async Task <AccountType> IsBasicAccount(EncryptedMessage encryptedMessage) { // check password == Azure var result = await _healthyGamerPortalDbContext.ApplicationUsers.FirstOrDefaultAsync(I => I.Email == Rfc7905.DecryptText(encryptedMessage.Length, encryptedMessage.Text) && I.Password == "Discord"); if (result != null) { return(AccountType.Discord); } return(AccountType.Basic); }