Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Validation Attribute do some kind of caching?
- public class CurrentPasswordValidationAttribute : ValidationAttribute
- {
- private IWorkContext workContext;
- private ICryptoService cryptoService;
- public CurrentPasswordValidationAttribute() : this(IoCContainer.Resolve<IWorkContext>(), IoCContainer.Resolve<ICryptoService>()) { }
- public CurrentPasswordValidationAttribute(IWorkContext workContext, ICryptoService cryptoService)
- {
- this.workContext = workContext;
- this.cryptoService = cryptoService;
- }
- public override bool IsValid(object value)
- {
- if (value == null)
- return true;
- var user = workContext.CurrentUser;
- //var user = IoCContainer.Resolve<IWorkContext>().CurrentUser;
- return user.Password.SaltedAndHashedPassword == cryptoService.HashStringWithSHA256(string.Concat(value.ToString(), user.Password.Salt));
- }
- }
- public User CurrentUser
- {
- get
- {
- return userService.GetUserByEmail(HttpContext.Current.User.Identity.Name);
- }
- }
Add Comment
Please, Sign In to add comment