mirror of
https://github.com/moparisthebest/mail
synced 2024-11-21 16:35:04 -05:00
Merge pull request #327 from whiteout-io/dev/WO-950
[WO-03-018] Fix weak Passwords & Misleading Passphrase Strength Check (L...
This commit is contained in:
commit
94188be7b3
@ -21,59 +21,6 @@ var SetPassphraseCtrl = function($scope, $q, pgp, keychain, dialog) {
|
||||
// scope functions
|
||||
//
|
||||
|
||||
/*
|
||||
* Taken from jQuery validate.password plug-in 1.0
|
||||
* http://bassistance.de/jquery-plugins/jquery-plugin-validate.password/
|
||||
*
|
||||
* Copyright (c) 2009 Jörn Zaefferer
|
||||
*
|
||||
* Licensed under the MIT
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
*/
|
||||
$scope.checkPassphraseQuality = function() {
|
||||
var passphrase = $scope.newPassphrase;
|
||||
$scope.passphraseRating = 0;
|
||||
|
||||
var LOWER = /[a-z]/,
|
||||
UPPER = /[A-Z]/,
|
||||
DIGIT = /[0-9]/,
|
||||
DIGITS = /[0-9].*[0-9]/,
|
||||
SPECIAL = /[^a-zA-Z0-9]/,
|
||||
SAME = /^(.)\1+$/;
|
||||
|
||||
function uncapitalize(str) {
|
||||
return str.substring(0, 1).toLowerCase() + str.substring(1);
|
||||
}
|
||||
|
||||
if (!passphrase) {
|
||||
// no rating for empty passphrase
|
||||
$scope.passphraseMsg = '';
|
||||
return;
|
||||
}
|
||||
|
||||
if (passphrase.length < 8 || SAME.test(passphrase)) {
|
||||
$scope.passphraseMsg = 'Very weak';
|
||||
return;
|
||||
}
|
||||
|
||||
var lower = LOWER.test(passphrase),
|
||||
upper = UPPER.test(uncapitalize(passphrase)),
|
||||
digit = DIGIT.test(passphrase),
|
||||
digits = DIGITS.test(passphrase),
|
||||
special = SPECIAL.test(passphrase);
|
||||
|
||||
if (lower && upper && digit || lower && digits || upper && digits || special) {
|
||||
$scope.passphraseMsg = 'Strong';
|
||||
$scope.passphraseRating = 3;
|
||||
} else if (lower && upper || lower && digit || upper && digit) {
|
||||
$scope.passphraseMsg = 'Good';
|
||||
$scope.passphraseRating = 2;
|
||||
} else {
|
||||
$scope.passphraseMsg = 'Weak';
|
||||
$scope.passphraseRating = 1;
|
||||
}
|
||||
};
|
||||
|
||||
$scope.setPassphrase = function() {
|
||||
var keyId = pgp.getKeyParams()._id;
|
||||
|
||||
|
@ -10,10 +10,6 @@
|
||||
margin-bottom: 10px;
|
||||
color: $color-error;
|
||||
}
|
||||
&__password-strong-message {
|
||||
margin-bottom: 10px;
|
||||
color: green;
|
||||
}
|
||||
|
||||
&__row {
|
||||
margin-bottom: 10px;
|
||||
|
@ -16,12 +16,11 @@
|
||||
<input class="input-text" type="password" ng-model="oldPassphrase" placeholder="Current passphrase" tabindex="1" wo-focus-me="true">
|
||||
</div>
|
||||
|
||||
<p class="form__error-message" ng-show="passphraseMsg && passphraseRating < 2">{{passphraseMsg}}</p>
|
||||
<p class="form__password-strong-message" ng-show="passphraseMsg && passphraseRating >= 2">{{passphraseMsg}}</p>
|
||||
<p class="form__error-message" ng-show="passphraseMsg">{{passphraseMsg}}</p>
|
||||
<div class="form__row form__row--multi">
|
||||
<div class="form__col">
|
||||
<input class="input-text" type="password" ng-model="newPassphrase"
|
||||
placeholder="New passphrase" ng-change="checkPassphraseQuality()" tabindex="2">
|
||||
placeholder="New passphrase" tabindex="2">
|
||||
</div>
|
||||
<div class="form__col">
|
||||
<input class="input-text" type="password" ng-model="confirmation" placeholder="Confirm passphrase"
|
||||
|
@ -79,46 +79,4 @@ describe('Set Passphrase Controller unit test', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('check passphrase quality', function() {
|
||||
it('should be too short', function() {
|
||||
scope.newPassphrase = '&§DG36';
|
||||
scope.checkPassphraseQuality();
|
||||
|
||||
expect(scope.passphraseMsg).to.equal('Very weak');
|
||||
expect(scope.passphraseRating).to.equal(0);
|
||||
});
|
||||
|
||||
it('should be very weak', function() {
|
||||
scope.newPassphrase = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
|
||||
scope.checkPassphraseQuality();
|
||||
|
||||
expect(scope.passphraseMsg).to.equal('Very weak');
|
||||
expect(scope.passphraseRating).to.equal(0);
|
||||
});
|
||||
|
||||
it('should be weak', function() {
|
||||
scope.newPassphrase = 'asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf';
|
||||
scope.checkPassphraseQuality();
|
||||
|
||||
expect(scope.passphraseMsg).to.equal('Weak');
|
||||
expect(scope.passphraseRating).to.equal(1);
|
||||
});
|
||||
|
||||
it('should be good', function() {
|
||||
scope.newPassphrase = 'asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf5';
|
||||
scope.checkPassphraseQuality();
|
||||
|
||||
expect(scope.passphraseMsg).to.equal('Good');
|
||||
expect(scope.passphraseRating).to.equal(2);
|
||||
});
|
||||
|
||||
it('should be strong', function() {
|
||||
scope.newPassphrase = '&§DG36abcd';
|
||||
scope.checkPassphraseQuality();
|
||||
|
||||
expect(scope.passphraseMsg).to.equal('Strong');
|
||||
expect(scope.passphraseRating).to.equal(3);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user