Class PasswordUtil
- java.lang.Object
-
- com.healthmarketscience.jackcess.crypt.PasswordUtil
-
public class PasswordUtil extends Object
Adds, changes and removes the database password on a database. The current password can be read withDatabase.getDatabasePassword(), which needs nothing from this library.Only jet 4 databases (mdb files written by access 2000 and 2003) are supported, and the other formats throw rather than write something ms access cannot open:
- jet 3 stores the password field without the creation date mask, and has not been verified
- in an accdb, a database password means the file is encrypted, which is
a different mechanism entirely (see
CryptCodecProvider) - msisam (money) files feed the password into the page encoding key
Setting a password changes the page 0 header and rewrites every SID in the database, and the two have to agree or ms access prompts for the password and then refuses to open the file. An interruption part way through leaves the database in exactly that state, and re-running the operation does not repair it, because the key is derived from the header the run starts with.
The forms which take a
Pathare safe from that. They build a separate file and replace the original only once it is complete, so an interrupted operation leaves the original database as it was. The in place form gives the database a new identity on disk, which drops any hard link to it. The forms which take an openDatabaseare not, because the caller holds the file, so copy it first.The database must not be in use, and an open one must be open for writing.
- Author:
- James Ahlborn
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidremoveDatabasePassword(Database db)Removes the database password from the given database.static voidremoveDatabasePassword(Path dbFile)Removes the database password from the given database, replacing the file with the result.static voidremoveDatabasePassword(Path srcFile, Path dstFile)Writes a copy of the given database with no password, leaving the source alone.static voidsetDatabasePassword(Database db, String password)Sets the database password on the given database, replacing any existing one.static voidsetDatabasePassword(Path dbFile, String password)Sets the database password on the given database, replacing the file with the result.static voidsetDatabasePassword(Path srcFile, Path dstFile, String password)Writes a copy of the given database with the given password, leaving the source alone.
-
-
-
Method Detail
-
setDatabasePassword
public static void setDatabasePassword(Database db, String password) throws IOException
Sets the database password on the given database, replacing any existing one.- Parameters:
db- the database to modify, open for writingpassword- the new password, which may not benullor empty- Throws:
IOException
-
setDatabasePassword
public static void setDatabasePassword(Path dbFile, String password) throws IOException
Sets the database password on the given database, replacing the file with the result.- Parameters:
dbFile- the database to modify, not in usepassword- the new password, which may not benullor empty- Throws:
IOException
-
setDatabasePassword
public static void setDatabasePassword(Path srcFile, Path dstFile, String password) throws IOException
Writes a copy of the given database with the given password, leaving the source alone.- Parameters:
srcFile- the database to copy, not in usedstFile- the file to write, overwritten if it existspassword- the new password, which may not benullor empty- Throws:
IOException
-
removeDatabasePassword
public static void removeDatabasePassword(Database db) throws IOException
Removes the database password from the given database. Does nothing if it does not have one.- Parameters:
db- the database to modify, open for writing- Throws:
IOException
-
removeDatabasePassword
public static void removeDatabasePassword(Path dbFile) throws IOException
Removes the database password from the given database, replacing the file with the result. Does nothing to the password if it does not have one.- Parameters:
dbFile- the database to modify, not in use- Throws:
IOException
-
removeDatabasePassword
public static void removeDatabasePassword(Path srcFile, Path dstFile) throws IOException
Writes a copy of the given database with no password, leaving the source alone.- Parameters:
srcFile- the database to copy, not in usedstFile- the file to write, overwritten if it exists- Throws:
IOException
-
-