From 7e0ccd16e83f606bc7117742a96f44c8fa3fcd2b Mon Sep 17 00:00:00 2001 From: Alexander Bell Date: Sun, 30 Sep 2018 12:23:40 +0200 Subject: [PATCH] regenerate random password, some layout changes --- src/components/PasswordManager/Edit.js | 49 +++++++++++--- src/components/PasswordManager/New.js | 68 ++++++++++++-------- src/pages/passwordManager/PasswordManager.js | 17 +++-- src/stores/functions/generatePassword.js | 15 +++++ 4 files changed, 108 insertions(+), 41 deletions(-) create mode 100644 src/stores/functions/generatePassword.js diff --git a/src/components/PasswordManager/Edit.js b/src/components/PasswordManager/Edit.js index 4baceb6..9494763 100644 --- a/src/components/PasswordManager/Edit.js +++ b/src/components/PasswordManager/Edit.js @@ -9,6 +9,7 @@ import alertify from 'alertify.js'; * Functions import */ import { encrypt, decrypt } from '../../stores/functions/encryption'; +import { generatePassword } from '../../stores/functions/generatePassword'; /* * Component imports @@ -57,6 +58,7 @@ const Edit = inject("rootStore") ( observer( this.handleChange = this.handleChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); + this.dice = this.dice.bind(this); this.state = { url: '', @@ -116,6 +118,15 @@ const Edit = inject("rootStore") ( observer( } + dice() { + //Generate a new random password + + this.setState({ + password: generatePassword() + }); + } + + handleSubmit() { const url = this.state.url; const login = encrypt(this.state.login, this.props.encryptionkey); @@ -172,25 +183,45 @@ const Edit = inject("rootStore") ( observer(
- - - + - - - + - - - + } + labelPosition="right" + required + /> + +

Login and password are going to be encrypted with the key you have set.

diff --git a/src/components/PasswordManager/New.js b/src/components/PasswordManager/New.js index 63ad04e..2c794e0 100644 --- a/src/components/PasswordManager/New.js +++ b/src/components/PasswordManager/New.js @@ -9,6 +9,7 @@ import alertify from 'alertify.js'; * Functions import */ import { encrypt } from '../../stores/functions/encryption'; +import { generatePassword } from '../../stores/functions/generatePassword'; /* * Component imports @@ -57,11 +58,12 @@ const New = inject("rootStore") ( observer( this.handleChange = this.handleChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); + this.dice = this.dice.bind(this); this.state = { url: '', login: '', - password: this.generatePassword(), + password: generatePassword(), loading: false } @@ -80,7 +82,7 @@ const New = inject("rootStore") ( observer( this.setState({ url: '', login: '', - password: this.generatePassword() + password: generatePassword() }); } } @@ -98,23 +100,6 @@ const New = inject("rootStore") ( observer( } - generatePassword() { - //Creates a unique id for each chat bubble so that the animation can be triggered - - var random = ""; - var possible = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP0123456"; - - for (var i = 0; i < 16; i++) - random += possible.charAt(Math.floor(Math.random() * possible.length)); - - while(true) { - if(!document.getElementById(random)) { - return random; - } - } - } - - handleChange(e) { this.setState({ [e.target.name]: e.target.value @@ -122,6 +107,15 @@ const New = inject("rootStore") ( observer( } + dice() { + //Generate a new random password + + this.setState({ + password: generatePassword() + }); + } + + handleSubmit() { const url = this.state.url; const login = encrypt(this.state.login, this.props.encryptionkey); @@ -177,23 +171,41 @@ const New = inject("rootStore") ( observer( - - - + - - - + - - - + } + labelPosition="right" + required + />

Login and password are going to be encrypted with the key you have set.

diff --git a/src/pages/passwordManager/PasswordManager.js b/src/pages/passwordManager/PasswordManager.js index ebf3618..78f1af4 100644 --- a/src/pages/passwordManager/PasswordManager.js +++ b/src/pages/passwordManager/PasswordManager.js @@ -239,13 +239,13 @@ const PasswordManager = inject("rootStore") ( observer( {url} {login} - {password} - @@ -269,9 +269,18 @@ const PasswordManager = inject("rootStore") ( observer( - - + + diff --git a/src/stores/functions/generatePassword.js b/src/stores/functions/generatePassword.js new file mode 100644 index 0000000..21da3d3 --- /dev/null +++ b/src/stores/functions/generatePassword.js @@ -0,0 +1,15 @@ +export function generatePassword() { + //Creates a unique id for each chat bubble so that the animation can be triggered + + var random = ""; + var possible = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP0123456"; + + for (var i = 0; i < 16; i++) + random += possible.charAt(Math.floor(Math.random() * possible.length)); + + while(true) { + if(!document.getElementById(random)) { + return random; + } + } +} \ No newline at end of file