I am writing a 3-level application using NHibernate, where the password of the account is saved as a hash in the database Go.
The presentation level calls a save method, which an account unit wants, in my service, where it has become a password before giving it to the repository.
So, for the first time an account is saved, the password has been done correctly and everything is fine.
But once I have to update an account, without changing my password
My entity looks like this:
public class accountability: EntityBase {public virtual string username {get; Set; } Public Virtual String Password {get; Set; } Public Virtual String Email {get; Set; } Public Virtual Boole enabled {get; Set; }} and my service with the save method:
Public class account service {Private Redonii irapposy & lt; AccountType & gt; _accountRepository; Private Readonly IHashingProvider _hashingProvider; Public Account Service (IRPOSITORY & Lieutenant; Accountancy> Account Repository, IhashingProvider Hashing Provider) {_accountRepository = accountRepository; _hashingProvider = hashingProvider; } Public Zero Save (Accountancy Accountancy) {accountEntity.Password = _hashingProvider.Hash (accountEntity.Password); _accountRepository.Save (accountEntity); }} How can I tell NHibernate not to update passwords? What other possibilities do I have?
I suggest to handle it in a way that does not deal with it simply with the NHibernate layer " Separate the "first-generation" operation (which requires healing) from the general saving of any update "operation (which does not require hashing).
For example, to add an method to an account, account service for the first time can be hashing and save () Can delegate. Usually save () then the object can continue normally. You can also add a method to make changes to the password, which can run a new password via a new password hash and calling save () .
Comments
Post a Comment