Permalink
Browse files

Master Password Feature

  • Loading branch information...
1 parent b4bdab6 commit f7782c58dd24174e71f1d616fc9b45f76f17355b @saenzramiro committed Sep 8, 2016
@@ -92,6 +92,45 @@ Ext.define('Rambox.view.preferences.Preferences',{
}
,{
xtype: 'fieldset'
+ ,title: 'Master Password - Ask for password on startup'
+ ,collapsed: !config.master_password
+ ,checkboxToggle: true
+ ,checkboxName: 'master_password'
+ ,margin: '10 0 0 0'
+ ,padding: 10
+ ,layout: 'hbox'
+ ,defaults: { labelAlign: 'top' }
+ ,items: [
+ {
+ xtype: 'textfield'
+ ,inputType: 'password'
+ ,fieldLabel: 'Password'
+ ,name: 'master_password1'
+ ,itemId: 'pass'
+ ,flex: 1
+ ,listeners: {
+ validitychange: function(field) {
+ field.next().validate();
+ },
+ blur: function(field) {
+ field.next().validate();
+ }
+ }
+ }
+ ,{
+ xtype: 'textfield'
+ ,inputType: 'password'
+ ,fieldLabel: 'Repeat Password'
+ ,name: 'master_password2'
+ ,margin: '0 0 0 10'
+ ,vtype: 'password'
+ ,initialPassField: 'pass'
+ ,flex: 1
+ }
+ ]
+ }
+ ,{
+ xtype: 'fieldset'
,title: 'Proxy (needs to relaunch) - <a href="http://proxylist.hidemyass.com/" target="_blank">Free IP:PORT Proxy List</a>'
,collapsed: !config.proxy
,checkboxToggle: true
@@ -13,6 +13,13 @@ Ext.define('Rambox.view.preferences.PreferencesController', {
var values = me.getView().down('form').getForm().getFieldValues();
+ // Master Password
+ if ( values.master_password && (Ext.isEmpty(values.master_password1) || Ext.isEmpty(values.master_password2)) ) return;
+ if ( values.master_password && (values.master_password1 !== values.master_password2) ) return;
+ if ( values.master_password ) values.master_password = Rambox.util.MD5.encypt(values.master_password1);
+ delete values.master_password1;
+ delete values.master_password2;
+
// Proxy
if ( values.proxy && (Ext.isEmpty(values.proxyHost) || Ext.isEmpty(values.proxyPort)) ) return;
View
@@ -27,6 +27,7 @@ const config = new Config({
,keep_in_taskbar_on_close: true
,start_minimized: false
,systemtray_indicator: true
+ ,master_password: false
,proxy: false
,proxyHost: ''
,proxyPort: ''
@@ -203,6 +204,16 @@ function createWindow () {
});
}
+let mainMasterPasswordWindow;
+function createMasterPasswordWindow() {
+ mainMasterPasswordWindow = new BrowserWindow({
+ backgroundColor: '#0675A0'
+ ,frame: false
+ });
+ mainMasterPasswordWindow.loadURL('file://' + __dirname + '/../masterpassword.html');
+ mainMasterPasswordWindow.on('close', function() { mainMasterPasswordWindow = null });
+}
+
function updateBadge(title) {
var messageCount = title.match(/\d+/g) ? parseInt(title.match(/\d+/g).join("")) : 0;
@@ -245,6 +256,15 @@ ipcMain.on('setConfig', function(event, values) {
updateBadge(mainWindow.getTitle());
});
+ipcMain.on('validateMasterPassword', function(event, pass) {
+ if ( config.get('master_password') === require('crypto').createHash('md5').update(pass).digest('hex') ) {
+ createWindow();
+ mainMasterPasswordWindow.close();
+ event.returnValue = true;
+ }
+ event.returnValue = false;
+});
+
// Handle Service Notifications
ipcMain.on('setServiceNotifications', function(event, partition, op) {
session.fromPartition(partition).setPermissionRequestHandler(function(webContents, permission, callback) {
@@ -354,7 +374,9 @@ if ( config.get('proxy') ) app.commandLine.appendSwitch('proxy-server', config.g
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
-app.on('ready', createWindow);
+app.on('ready', function() {
+ config.get('master_password') ? createMasterPasswordWindow() : createWindow();
+});
// Quit when all windows are closed.
app.on('window-all-closed', function () {
@@ -368,8 +390,8 @@ app.on('window-all-closed', function () {
app.on('activate', function () {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
- if (mainWindow === null) {
- createWindow();
+ if (mainWindow === null && mainMasterPasswordWindow === null ) {
+ config.get('master_password') ? createMasterPasswordWindow() : createWindow();
}
});
View
@@ -0,0 +1,28 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
+ <title>Rambox</title>
+</head>
+<body>
+ <div style="background-image: url(resources/Icon.png);background-size:200px;width:200px;height:200px;position:relative;left:50%;margin-left:-100px;margin-top:100px;"></div>
+ <div style="color:#FFF;text-align:center;font-size:20px;font-family:Verdana;margin:30px 0;">Master Password</div>
+ <div style="text-align:center;margin:30px 0;"><input type="password" autofocus placeholder="Enter your password..." onkeyup="doValidate(this.value)" style="text-align:center;font-size:20px;font-family:Verdana;padding:10px;" /></div>
+ <script>
+ var to;
+ function doValidate(value) {
+ clearTimeout(to);
+ to = setTimeout(function() {
+ const {ipcRenderer} = require('electron');
+ if ( ipcRenderer.sendSync('validateMasterPassword', value) ) {
+ //require('electron').remote.
+ } else {
+ alert('The password is incorrect. Try again...');
+ }
+ }, 3000);
+ }
+ </script>
+</body>
+</html>
@@ -0,0 +1,37 @@
+Ext.apply(Ext.form.field.VTypes, {
+ daterange: function(val, field) {
+ var date = field.parseDate(val);
+
+ if (!date) {
+ return false;
+ }
+ if (field.startDateField && (!this.dateRangeMax || (date.getTime() != this.dateRangeMax.getTime()))) {
+ var start = field.up('form').down('#' + field.startDateField);
+ start.setMaxValue(date);
+ start.validate();
+ this.dateRangeMax = date;
+ } else if (field.endDateField && (!this.dateRangeMin || (date.getTime() != this.dateRangeMin.getTime()))) {
+ var end = field.up('form').down('#' + field.endDateField);
+ end.setMinValue(date);
+ end.validate();
+ this.dateRangeMin = date;
+ }
+ /*
+ * Always return true since we're only using this vtype to set the
+ * min/max allowed values (these are tested for after the vtype test)
+ */
+ return true;
+ },
+
+ daterangeText: 'Start date must be less than end date',
+
+ password: function(val, field) {
+ if (field.initialPassField) {
+ var pwd = field.up('form').down('#' + field.initialPassField);
+ return (val == pwd.getValue());
+ }
+ return true;
+ },
+
+ passwordText: 'Passwords do not match'
+});

0 comments on commit f7782c5

Please sign in to comment.