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 7752593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:50:21+00:00 2026-06-01T11:50:21+00:00

I use NHibernate and have a custom type for encrypting passwords in the database

  • 0

I use NHibernate and have a custom type for encrypting passwords in the database so that I can use string properties to represent passwords, but NHibernate transforms / encrypts the value before storing in the db. Currently, I store a salt value and an encryption key in the config file, but I’d really rather move to a password hash. However, the custom NHibernate type knows nothing about the object being stored other than the value of the property it is being told to handle, so I can’t generate some random salt and store it with the object in another property from within this custom type.

Since I can’t store the salt separately, I wonder if it would be OK to derive the salt from the password itself, and then hash the combination of the two. For example, I might take the password, MD5 hash it, then use the MD5 hash as the salt. Would this be OK? This would allow me to persist the password in a deterministic manner while using a unique (but derived) salt value per password, but are there any security considerations when doing it this way?

EDIT:

Because all of the answers I’ve received so far have failed to account for the context of the question, let me present the signature of the method defined in NHibernate terms.

public override void Set(IDbCommand cmd, object value, int index)
{
    var param = (IDataParameter)cmd.Parameters[index];

    if (value == null)
    {
        param.Value = null;
    }
    else
    {
        var temp = value.ToString();
        var encrypted = encryptor.Encrypt(temp);
        param.Value = encrypted;
    }
}

That’s all NHibernate gives me. I receive the IDbCommand object, a value, and a parameter index. I know nothing about the parameters themselves or the type of object being persisted. I only have a value. I cannot generate a random salt and store it in a separate property, because I do not know what properties exist on the object being persisted, nor which order they are stored in the parameter collection. My goal is to hash the password in the most secure way possible within the context of this method call. If you’re going to argue against my suggestion, it would be helpful to receive an alternative idea within this context.

  • 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-06-01T11:50:22+00:00Added an answer on June 1, 2026 at 11:50 am

    No! If you derive salt from the password all the same password have the same hash and the salt became useless.

    Try with

    var temp = value.ToString();
    var salt = generateRandonSalt();
    var encrypted = encryptor.Encrypt(temp + salt);
    param.Value = salt + encrypted;
    

    With “+” I mean a concatenation operand or something compatible with your value. And naturally you need to know always the salt length so you can check password next times.

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

Sidebar

Related Questions

I have a console command line app that use NHibernate . I am trying
For our test fixtures we use NHibernate to generate a database schema. We have
how exactly I can use public methods (non-virtual) with NHibernate? I have this code:
I have some EJBs that use Hibernate to persist data to the database. I
I have a table in my database that represents datafields in a custom form.
I have a custom user type that is used to map from a decimal
I have a class mapped with NHibernate and I'm trying to use a custom
I would like to be able to use custom string querying within my NHibernate
Is there any way in NHibernate that I can use the following Entities public
I'm a little confused. We have developed an net 4.0 application. We use nhibernate

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.