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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:50:33+00:00 2026-05-20T14:50:33+00:00

I am trying to hash a password and save it in the database; I

  • 0

I am trying to hash a password and save it in the database; I know hashing is a one way process. How can I check whether the user supplied password and the one stored in the database are same? I am using MD5 and I am getting different values for the same input when I perform hashing each time. Can anyone help?

String pass = "wor1ldcup";
    String pass1 = "wor1ldcup";

    DigestUtils du = new DigestUtils();
    byte[] b = du.md5(pass);
    byte[] b1 = du.md5(pass1);
  • 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-20T14:50:33+00:00Added an answer on May 20, 2026 at 2:50 pm

    The code you supplied is basically correct, with a couple of caveats:

    1. The methods of DigestUtils are all static, and hence should be invoked as:

      byte[] b = DigestUtils.md5(...);
      

      and not as

      DigestUtils du = new DigestUtils();  // wrong ... no need to instantiate
      byte[] b = du.md5(...);              // wrong ... never use an instance to
                                           //           call a static method.
      
    2. You don’t show how you compare the b and b1, but b == b1 won’t work, and neither will b.equals(b2) … both compare references. You need to call Arrays.equals(b, b1).

    3. It is a bad idea to try to turn an MD5 hash into a String. Depending on the default character set, the conversion may turn out to be lossy; i.e. not reversible. If you want to store an MD5 hash in a database, it is better to encode as a String using (for example) base64 encoding, and save the encoded hash.

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

Sidebar

Related Questions

I have a one-to-one relation between an Account and a User table, I'm trying
I am trying to build my own user authentication system (simply because the ones
I'm trying to create a Hash of Hash -es. The value of the 2nd
I am trying to share a multi-dimensional hash over multiple threads. This hash holds
I'm trying to authenticate a SOAP request using WS-UsernameToken spec, but the target device
I'm trying to convert this function into PHP but somehow it does not give
I'm trying to make a web service secure. It's not for a bank or
I am trying to implement hash_multimap in C++. Here is the code: #include <hash_map>
I want to be able to create users that have a straight up SHA-1
Consider the following table: mysql> select * from vCountryStatus; +-------------+------------+------+---------+--------+-----------------+ | CountryName | CountryISO

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.