Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
Matching Hashed and Salted Passwords from Database

I have built a custom realm using Apache Shiro to account for our application having more than one location for user accounts and stored passwords. Originally I was using Shiro to hash and match the passwords, but the custom realm means I have to do some of these things manually.

After looking I came across this code:

public String sha256(String base) {
    try{        
        MessageDigest digest = MessageDigest.getInstance("SHA-256");
        byte[] hash = digest.digest(base.getBytes("UTF-8"));
        StringBuffer hexString = new StringBuffer();

        for (int i = 0; i < hash.length; i++) {
            String hex = Integer.toHexString(0xff & hash[i]);
            if(hex.length() == 1) hexString.append('0');
            hexString.append(hex);
        }

        return hexString.toString();
    } catch(Exception ex){
       throw new RuntimeException(ex);
    }
}

I added a salt and it works great, so I'm wondering if I can just store the returned value in a database when creating a username\password pair and then later retrieve it to match the provided password (plus the salt). That seems like it should work, but when I did this previously with Shiro the SHA256 password hasher did NOT return the same value with the same base password each time, yet it was able to always match it. I wanted to make sure I'm following a valid (and most importantly secure) methodology for handling passwords.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

A couple things: You can create a hash of a string buy using something like: new Sha256Hash(password, salt)

Take a look at this example

If you have multiple places your users are stored, you should probably have a different realm for each store .

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!