Guest User

Untitled

a guest
Aug 26th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. Validation Attribute do some kind of caching?
  2. public class CurrentPasswordValidationAttribute : ValidationAttribute
  3. {
  4. private IWorkContext workContext;
  5. private ICryptoService cryptoService;
  6.  
  7. public CurrentPasswordValidationAttribute() : this(IoCContainer.Resolve<IWorkContext>(), IoCContainer.Resolve<ICryptoService>()) { }
  8.  
  9. public CurrentPasswordValidationAttribute(IWorkContext workContext, ICryptoService cryptoService)
  10. {
  11. this.workContext = workContext;
  12. this.cryptoService = cryptoService;
  13. }
  14.  
  15. public override bool IsValid(object value)
  16. {
  17. if (value == null)
  18. return true;
  19.  
  20. var user = workContext.CurrentUser;
  21. //var user = IoCContainer.Resolve<IWorkContext>().CurrentUser;
  22.  
  23. return user.Password.SaltedAndHashedPassword == cryptoService.HashStringWithSHA256(string.Concat(value.ToString(), user.Password.Salt));
  24. }
  25. }
  26.  
  27. public User CurrentUser
  28. {
  29. get
  30. {
  31. return userService.GetUserByEmail(HttpContext.Current.User.Identity.Name);
  32. }
  33. }
Add Comment
Please, Sign In to add comment