Fix password error

pull/332/head
Beaudan 6 years ago
parent 0aaccf2068
commit 5887f8c14c

@ -785,7 +785,7 @@ function _initializePaths(configDir) {
filePath = path.join(dbDir, 'db.sqlite'); filePath = path.join(dbDir, 'db.sqlite');
} }
async function initialize({ configDir, key, messages }) { async function initialize({ configDir, key, messages, passwordAttempt }) {
if (db) { if (db) {
throw new Error('Cannot initialize more than once!'); throw new Error('Cannot initialize more than once!');
} }
@ -828,6 +828,9 @@ async function initialize({ configDir, key, messages }) {
// test database // test database
await getMessageCount(); await getMessageCount();
} catch (error) { } catch (error) {
if (passwordAttempt) {
throw error;
}
console.log('Database startup error:', error.stack); console.log('Database startup error:', error.stack);
const buttonIndex = dialog.showMessageBox({ const buttonIndex = dialog.showMessageBox({
buttons: [ buttons: [

@ -746,10 +746,11 @@ app.on('ready', async () => {
// Try to show the main window with the default key // Try to show the main window with the default key
// If that fails then show the password window // If that fails then show the password window
try { const passwordSet = userConfig.get('passwordSet');
await showMainWindow(key); if (passwordSet) {
} catch (e) {
showPasswordWindow(); showPasswordWindow();
} else {
await showMainWindow(key);
} }
}); });
@ -779,13 +780,14 @@ async function removeDB() {
} }
} }
async function showMainWindow(sqlKey) { async function showMainWindow(sqlKey, passwordAttempt = false) {
const userDataPath = await getRealPath(app.getPath('userData')); const userDataPath = await getRealPath(app.getPath('userData'));
await sql.initialize({ await sql.initialize({
configDir: userDataPath, configDir: userDataPath,
key: sqlKey, key: sqlKey,
messages: locale.messages, messages: locale.messages,
passwordAttempt,
}); });
await sqlChannels.initialize(); await sqlChannels.initialize();
@ -1009,7 +1011,8 @@ ipc.on('password-window-login', async (event, passPhrase) => {
event.sender.send('password-window-login-response', e); event.sender.send('password-window-login-response', e);
try { try {
await showMainWindow(passPhrase); const passwordAttempt = true;
await showMainWindow(passPhrase, passwordAttempt);
sendResponse(); sendResponse();
if (passwordWindow) { if (passwordWindow) {
passwordWindow.close(); passwordWindow.close();
@ -1041,10 +1044,12 @@ ipc.on('set-password', async (event, passPhrase, oldPhrase) => {
const defaultKey = getDefaultSQLKey(); const defaultKey = getDefaultSQLKey();
await sql.setSQLPassword(defaultKey); await sql.setSQLPassword(defaultKey);
await sql.removePasswordHash(); await sql.removePasswordHash();
userConfig.set('passwordSet', false);
} else { } else {
await sql.setSQLPassword(passPhrase); await sql.setSQLPassword(passPhrase);
const newHash = passwordUtil.generateHash(passPhrase); const newHash = passwordUtil.generateHash(passPhrase);
await sql.savePasswordHash(newHash); await sql.savePasswordHash(newHash);
userConfig.set('passwordSet', true);
} }
sendResponse(); sendResponse();

@ -11,6 +11,10 @@ const localeMessages = ipcRenderer.sendSync('locale-data');
window.theme = config.theme; window.theme = config.theme;
window.i18n = i18n.setup(locale, localeMessages); window.i18n = i18n.setup(locale, localeMessages);
window.getEnvironment = () => config.environment;
window.getVersion = () => config.version;
window.getAppInstance = () => config.appInstance;
// So far we're only using this for Signal.Types // So far we're only using this for Signal.Types
const Signal = require('./js/modules/signal'); const Signal = require('./js/modules/signal');
@ -20,10 +24,6 @@ window.Signal = Signal.setup({
getRegionCode: () => null, getRegionCode: () => null,
}); });
window.getEnvironment = () => config.environment;
window.getVersion = () => config.version;
window.getAppInstance = () => config.appInstance;
window.passwordUtil = require('./app/password_util'); window.passwordUtil = require('./app/password_util');
window.resetDatabase = () => { window.resetDatabase = () => {

Loading…
Cancel
Save