Package util
Class PasswordUtil
java.lang.Object
util.PasswordUtil
Utility class for password hashing and verification
Uses SHA-256 with salt for secure password storage
- Author:
- TAMIL MUGHILAN
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
Generates a secure random salt.static String
hashPassword
(String password, String salt) Hashes a password using SHA-256 with the provided salt.static boolean
verifyPassword
(String password, String salt, String hashedPassword) Verifies if a password matches the stored hash.
-
Constructor Details
-
PasswordUtil
public PasswordUtil()
-
-
Method Details
-
hashPassword
Hashes a password using SHA-256 with the provided salt.- Parameters:
password
- the plain text password to hashsalt
- the salt to use for hashing- Returns:
- the hashed password as hexadecimal string
- Throws:
RuntimeException
- if SHA-256 algorithm is not available
-
generateSalt
Generates a secure random salt. Uses SecureRandom to generate 16 random bytes.- Returns:
- the generated salt as hexadecimal string
-
verifyPassword
Verifies if a password matches the stored hash. Hashes the provided password with salt and compares.- Parameters:
password
- the plain text password to verifysalt
- the salt used for the stored hashhashedPassword
- the stored hashed password- Returns:
- true if password matches, false otherwise
-