public class PasswordUtil
extends java.lang.Object
| Constructor and Description |
|---|
PasswordUtil() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
encodeMd5(java.lang.String user,
char[] password)
Deprecated.
prefer
PGConnection.alterUserPassword(String, char[], String)
or encodeScramSha256(char[]) for better security. |
static java.lang.String |
encodePassword(java.lang.String user,
char[] password,
java.lang.String encryptionType)
Encode the given password for the specified encryption type.
|
static java.lang.String |
encodeScramSha256(char[] password)
Encode the given password for SCRAM-SHA-256 authentication using the default
iteration count and a random salt.
|
static java.lang.String |
encodeScramSha256(char[] password,
int iterations,
byte[] salt)
Generate the encoded text representation of the given password for
SCRAM-SHA-256 authentication.
|
static java.lang.String |
genAlterUserPasswordSQL(java.lang.String user,
char[] password,
java.lang.String encryptionType)
Generate the SQL statement to alter a user's password using the given
encryption.
|
public static java.lang.String encodeScramSha256(char[] password,
int iterations,
byte[] salt)
password - The plain text of the user's password. The implementation will zero out
the array after useiterations - The number of iterations of the hashing algorithm to
performsalt - The random salt valuepublic static java.lang.String encodeScramSha256(char[] password)
password - The plain text of the user's password. The implementation will zero out the
array after use@Deprecated
public static java.lang.String encodeMd5(java.lang.String user,
char[] password)
PGConnection.alterUserPassword(String, char[], String)
or encodeScramSha256(char[]) for better security.user - The username of the database userpassword - The plain text of the user's password. The implementation will zero out the
array after usepublic static java.lang.String encodePassword(java.lang.String user,
char[] password,
java.lang.String encryptionType)
throws java.sql.SQLException
user - The username of the database userpassword - The plain text of the user's password. The implementation will zero
out the array after useencryptionType - The encryption type for which to encode the user's
password. This should match the database's supported
methods and value of the password_encryption setting.java.sql.SQLException - If an error occurs encoding the passwordpublic static java.lang.String genAlterUserPasswordSQL(java.lang.String user,
char[] password,
java.lang.String encryptionType)
throws java.sql.SQLException
user - The username of the database userpassword - The plain text of the user's password. The implementation will zero
out the array after useencryptionType - The encryption type of the passwordjava.sql.SQLException - If an error occurs encoding the passwordCopyright © 2025 PostgreSQL Global Development Group. All rights reserved.