public void Decrypt(string cvv) { CardNumber = StringEncryptionHelper.Decrypt(CardNumber, cvv); CardHolderFullName = StringEncryptionHelper.Decrypt(CardHolderFullName, cvv); Expiration = StringEncryptionHelper.Decrypt(Expiration, cvv); Cvv = StringEncryptionHelper.Decrypt(Cvv); }
public void Encrypt() { CardNumber = StringEncryptionHelper.Encrypt(CardNumber, Cvv); CardHolderFullName = StringEncryptionHelper.Encrypt(CardHolderFullName, Cvv); Expiration = StringEncryptionHelper.Encrypt(Expiration, Cvv); Cvv = StringEncryptionHelper.Encrypt(Cvv); }
private async Task ValidatePaymentHistoryAddingAsync(AddPaymentHistoryDto paymentHistoryDto, CancellationToken ct) { var paymentMethodDto = await _unitOfWork.PaymentMethodRepository.GetAsync(paymentHistoryDto.PaymentMethodId, ct); if (paymentMethodDto == null) { _logger.LogInformation("Payment method with id {PaymentMethodId} not found", paymentHistoryDto.PaymentMethodId); throw new ItemNotFoundException(); } if (paymentMethodDto.AccountId != paymentHistoryDto.AccountId) { _logger.LogInformation("Access to this payment method is not allowed for account {AccountId}", paymentHistoryDto.AccountId); throw new AccessToItemForbiddenException(); } var isAlreadyPaid = await _unitOfWork.PaymentHistoryRepository.IsExistsAsync(paymentMethodDto.AccountId, paymentHistoryDto.OrderId, ct); if (isAlreadyPaid) { _logger.LogInformation("Order with Id {OrderId} already paid", paymentHistoryDto.OrderId); throw new OrderAlreadyPaidException(); } if (paymentMethodDto.Cvv != StringEncryptionHelper.Encrypt(paymentHistoryDto.Cvv)) { _logger.LogInformation("Cvv code for payment method {PaymentMethodId} is wrong", paymentHistoryDto.PaymentMethodId); throw new CvvIsWrongException(); } }
public UserAccounts GetEntityByCredentials(string name, string password) { using (var context = new GcblPrincipalDatabase()) { var foundUser = context.UserAccounts.FirstOrDefault(entity => entity.UserName.Equals(name, StringComparison.InvariantCultureIgnoreCase)); if (foundUser != null && StringEncryptionHelper.Decrypt(foundUser.Password) .Equals(password, StringComparison.InvariantCulture)) { return(foundUser); } return(null); } }
public async Task ReceiveAsync(AuthenticationTokenReceiveContext context) { var allowedOrigin = context.OwinContext.Get <string>("as:clientAllowedOrigin"); context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin }); string hashedTokenId = StringEncryptionHelper.GetHash(context.Token); var refreshToken = await ContainerManager.Resolve <IAuthRepository>().FindRefreshToken(hashedTokenId); if (refreshToken != null) { //Get protectedTicket from refreshToken class context.DeserializeTicket(refreshToken.ProtectedTicket); var result = await ContainerManager.Resolve <IAuthRepository>().RemoveRefreshToken(hashedTokenId); } }
public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context) { string clientId = string.Empty; string clientSecret = string.Empty; AppClientInfo client = null; if (!context.TryGetBasicCredentials(out clientId, out clientSecret)) { context.TryGetFormCredentials(out clientId, out clientSecret); } if (context.ClientId == null) { //Remove the comments from the below line context.SetError, and invalidate context //if you want to force sending clientId/secrects once obtain access tokens. context.Validated(); //context.SetError("invalid_clientId", "ClientId should be sent."); return(Task.FromResult <object>(null)); } client = ContainerManager.Resolve <IAuthRepository>().FindClient(context.ClientId); if (client == null) { context.SetError("invalid_clientId", $"Client '{context.ClientId}' is not registered in the system."); context.SetError("res_code", "60004"); context.SetError("res_msg", "登录失败"); return(Task.FromResult <object>(null)); } if (!(client.ApplicationType == 1)) { if (string.IsNullOrWhiteSpace(clientSecret)) { context.SetError("invalid_clientId", "Client secret should be sent."); context.SetError("res_code", "60003"); context.SetError("res_msg", "登录失败"); return(Task.FromResult <object>(null)); } else { if (client.Secret != StringEncryptionHelper.GetHash(clientSecret)) { context.SetError("invalid_clientId", "Client secret is invalid."); context.SetError("res_code", "60002"); context.SetError("res_msg", "登录失败"); return(Task.FromResult <object>(null)); } } } if (!client.Active) { context.SetError("invalid_clientId", "Client is inactive."); context.SetError("res_code", "60001"); context.SetError("res_msg", "登录失败"); return(Task.FromResult <object>(null)); } context.OwinContext.Set <string>("as:clientAllowedOrigin", client.AllowedOrigin); context.OwinContext.Set <string>("as:clientRefreshTokenLifeTime", client.RefreshTokenLifeTime.ToString()); context.Validated(); return(base.ValidateClientAuthentication(context)); }