Skip to content

Commit

Permalink
Merge pull request #528 from EagleEye25/password-creation-verification
Browse files Browse the repository at this point in the history
added password verification
  • Loading branch information
pciavald committed Jan 5, 2018
2 parents e863851 + 345026b commit 9bbb096
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 11 deletions.
13 changes: 12 additions & 1 deletion src/app/modals/createwallet/createwallet.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@
[showStakeOnly]="false">
</app-password>
</div>
<!--Confirmation of password-->
<div *ngIf="step === 2">
<app-password
#passwordElementVerify
label="Verify Password"
[emitPassword]="true"
(passwordEmitter)="passwordFromEmitter($event, true)"
[showStakeOnly]="false">
</app-password>
</div>

<ng-template [ngIf]="[3,4].indexOf(step) != -1">
<app-passphrase
Expand Down Expand Up @@ -233,7 +243,8 @@

<div class="title">Congratulations!</div>
<p>
Your new wallet was created successfully and set as the default wallet!
Your new wallet was created successfully and set as the default wallet!<br>
<b>Please ensure that your Passphrase is written down and stored in a secure location!</b>
</p>
<div class="actions">
<button mat-raised-button color="primary" (click)="close()">
Expand Down
51 changes: 41 additions & 10 deletions src/app/modals/createwallet/createwallet.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { PassphraseComponent } from './passphrase/passphrase.component';
import { PassphraseService } from './passphrase/passphrase.service';

import { StateService } from '../../core/core.module';
import { SnackbarService } from '../../core/snackbar/snackbar.service';

@Component({
selector: 'modal-createwallet',
Expand All @@ -31,10 +32,12 @@ export class CreateWalletComponent {
@ViewChild('nameField') nameField: ElementRef;

password: string;
passwordVerify: string;
words: string[];

@ViewChild('passphraseComponent') passphraseComponent: ComponentRef<PassphraseComponent>;
@ViewChild('passwordElement') passwordElement: PasswordComponent;
@ViewChild('passwordElementVerify') passwordElementVerify: PasswordComponent;
@ViewChild('passwordRestoreElement') passwordRestoreElement: PasswordComponent;

// Used for verification
Expand All @@ -48,6 +51,7 @@ export class CreateWalletComponent {
private _modalsService: ModalsService,
private _passphraseService: PassphraseService,
private state: StateService,
private flashNotification: SnackbarService,
private dialogRef: MatDialogRef<CreateWalletComponent>
) {
this.reset();
Expand All @@ -60,6 +64,7 @@ export class CreateWalletComponent {
this.isRestore = false;
this.name = '';
this.password = '';
this.passwordVerify = '';
this.errorString = '';
this.step = 0;
this.state.observe('encryptionstatus').take(2)
Expand Down Expand Up @@ -89,6 +94,8 @@ export class CreateWalletComponent {
/* Recovery password entered */
if (this.step === 2) {
this.passwordElement.sendPassword();
this.passwordElementVerify.sendPassword();
return;
}

if (this.validate()) {
Expand All @@ -115,16 +122,23 @@ export class CreateWalletComponent {
if (this.isRestore) {
this.step = 4;
}
this.password = undefined;
this.passwordVerify = undefined;
break;
case 3:
this._passphraseService.generateMnemonic(this.mnemonicCallback.bind(this), this.password);
this.flashNotification.open(
'Please remember to write down your recovery passphrase',
'warning');
break;
case 4:
while (this.words.reduce((prev, curr) => prev + +(curr === ''), 0) < 5) {
const k = Math.floor(Math.random() * 23);

this.words[k] = '';
}
this.flashNotification.open(
'Did you write your password at the previous step ?',
'warning');
break;
case 5:
this.step = 4;
Expand Down Expand Up @@ -209,17 +223,34 @@ export class CreateWalletComponent {
this.passwordRestoreElement.sendPassword();
}

/**
* Triggered when the password is emitted from PasswordComponent
*/
passwordFromEmitter(pass: IPassword): void {
this.password = pass.password;
this.log.d(`passwordFromEmitter: ${this.password}`);
/** Triggered when the password is emitted from PasswordComponent */
passwordFromEmitter(pass: IPassword, verify?: boolean) {
this[verify ? 'passwordVerify' : 'password'] = pass.password;
this.log.d(`passwordFromEmitter: ${this.password} ${verify}`);
if (!!this[verify ? 'password' : 'passwordVerify'] ||
this.password === undefined && this.passwordVerify === undefined) {
this.verifyPasswords();
}
}

/**
* Triggered when the password is emitted from PassphraseComponent
*/
/** verify if passwords match */
verifyPasswords() {
if (!this.validating) {
return;
}

if (this.password !== this.passwordVerify) {
this.flashNotification.open('Passwords Do Not Match!', 'warning');
} else {
// We should probably make this a function because it isn't reusing code??
this.validating = false;
this.step++;
this.doStep();
}
this.passwordVerify = undefined;
}

/** Triggered when the password is emitted from PassphraseComponent */
wordsFromEmitter(words: string): void {
this.words = words.split(',');
}
Expand Down

0 comments on commit 9bbb096

Please sign in to comment.