Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4066448
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:07:54+00:00 2026-05-20T16:07:54+00:00

I’m writing a 3-tier application using NHibernate where account passwords are saved as hash

  • 0

I’m writing a 3-tier application using NHibernate where account passwords are saved as hash in a database.

The presentation layer calls a save method, that wants an account entity, in my service, where the password gets hashed before giving it to the repository.

So, first time an account gets saved, the password gets correctly hashed and everything is fine.

But once I have to update an account, without changing the password, the value of the password property in the account entity, is already hashed, when it gets passed through the save method of my service, it will hashed again.

My entity looks like this:

public class AccountEntity : EntityBase {
    public virtual string Username { get; set; }
    public virtual string Password { get; set; }
    public virtual string Email { get; set; }
    public virtual bool Enabled { get; set; }
}

And my service with the save method:

public class AccountService {
    private readonly IRepository<AccountEntity> _accountRepository;
    private readonly IHashingProvider _hashingProvider;

    public AccountService(IRepository<AccountEntity> accountRepository, IHashingProvider hashingProvider) {
        _accountRepository = accountRepository;
        _hashingProvider = hashingProvider;
    }

    public void Save(AccountEntity accountEntity) {
        accountEntity.Password = _hashingProvider.Hash(accountEntity.Password);
        _accountRepository.Save(accountEntity);
    }
}

How can I tell NHibernate to NOT update the password? What other possibilities do I have?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T16:07:54+00:00Added an answer on May 20, 2026 at 4:07 pm

    I’d suggest tackling this in a way that doesn’t deal with the NHibernate layer. Simply separate the “first-time creation” operation (which requires hashing) from the “general save of any updates” operation (which doesn’t need hashing).

    For example, add a Create() method to your AccountService for creating the account the first time, which can do the hashing and delegate to Save(). The general Save() can then just persist the object normally.

    You could also add a method for persisting a change in password, which can run the newly-requested password through the hash and calling Save().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a reasonable size flat file database of text documents mostly saved in
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.