Skip to content

Commit

Permalink
Merge pull request #1800 from Bilb/fix-password-login-issue
Browse files Browse the repository at this point in the history
fix login with password
  • Loading branch information
Bilb authored Jul 28, 2021
2 parents d236ef9 + b447774 commit a2d3cc3
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions app/sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,15 @@ function getSQLCipherIntegrityCheck(db) {

function keyDatabase(db, key) {
// https://www.zetetic.net/sqlcipher/sqlcipher-api/#key
db.pragma(`key = "x'${key}'"`);
// If the password isn't hex then we need to derive a key from it

const deriveKey = HEX_KEY.test(key);

const value = deriveKey ? `'${key}'` : `"x'${key}'"`;

const pragramToRun = `key = ${value}`;

db.pragma(pragramToRun);
}

function switchToWAL(db) {
Expand Down Expand Up @@ -269,13 +277,7 @@ function openAndMigrateDatabase(filePath, key) {
}
}

const INVALID_KEY = /[^0-9A-Fa-f]/;
function openAndSetUpSQLCipher(filePath, { key }) {
const match = INVALID_KEY.exec(key);
if (match) {
throw new Error(`setupSQLCipher: key '${key}' is not valid`);
}

return openAndMigrateDatabase(filePath, key);
}

Expand Down

0 comments on commit a2d3cc3

Please sign in to comment.