Package util

Class PasswordUtil

java.lang.Object
util.PasswordUtil

public class PasswordUtil extends Object
Utility class for password hashing and verification Uses SHA-256 with salt for secure password storage
Author:
TAMIL MUGHILAN
  • Constructor Details

    • PasswordUtil

      public PasswordUtil()
  • Method Details

    • hashPassword

      public static String hashPassword(String password, String salt)
      Hashes a password using SHA-256 with the provided salt.
      Parameters:
      password - the plain text password to hash
      salt - the salt to use for hashing
      Returns:
      the hashed password as hexadecimal string
      Throws:
      RuntimeException - if SHA-256 algorithm is not available
    • generateSalt

      public static String generateSalt()
      Generates a secure random salt. Uses SecureRandom to generate 16 random bytes.
      Returns:
      the generated salt as hexadecimal string
    • verifyPassword

      public static boolean verifyPassword(String password, String salt, String hashedPassword)
      Verifies if a password matches the stored hash. Hashes the provided password with salt and compares.
      Parameters:
      password - the plain text password to verify
      salt - the salt used for the stored hash
      hashedPassword - the stored hashed password
      Returns:
      true if password matches, false otherwise