Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1191 from gterzian/update_passowrd_strength_meter
Browse files Browse the repository at this point in the history
Issue #1178: Update password strength meter
  • Loading branch information
bartekn committed May 18, 2015
2 parents 90aa858 + 9b875c9 commit dc1380b
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 1,064 deletions.
3 changes: 1 addition & 2 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ <h1>Loading...</h1>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<script src="bower_components/ng-debounce/angular-debounce.js"></script>
<script src="bower_components/angular-password-strength/build/angular-password-strength.min.js"></script>
<script src="bower_components/autofill-event/src/autofill-event.js"></script>
<script src="bower_components/crypto-js/components/core.js"></script>
<script src="bower_components/crypto-js/components/ripemd160.js"></script>
Expand All @@ -113,6 +112,7 @@ <h1>Loading...</h1>
<script src="bower_components/angulartics/src/angulartics.js"></script>
<script src="bower_components/angulartics/src/angulartics-segmentio.js"></script>
<script src="bower_components/URIjs/src/URI.js"></script>
<script src="bower_components/zxcvbn/zxcvbn.js"></script>
<script src="scripts/utilities/sjcl.js"></script>
<script src="scripts/libraries/sjcl-scrypt.js"></script>
<!-- endbuild -->
Expand Down Expand Up @@ -231,7 +231,6 @@ <h1>Loading...</h1>
<script src="scripts/services/payment-history-service.js"></script>
<script src="scripts/services/contacts.js"></script>
<script src="scripts/services/invites.js"></script>
<script src="scripts/services/bad_passwords.js"></script>
<script src="scripts/services/action_link.js"></script>
<script src="scripts/services/gateways-service.js"></script>
<script src="scripts/services/validated-promise-service.js"></script>
Expand Down
1 change: 0 additions & 1 deletion app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ var stellarClient = angular.module('stellarClient', [
'debounce',
'singletonPromise',
'ui.router',
'vr.passwordStrength',
'ngClipboard',
'vcRecaptcha',
'ja.qr',
Expand Down
79 changes: 35 additions & 44 deletions app/scripts/controllers/password-controller.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
'use strict';
/* global zxcvbn*/

var sc = angular.module('stellarClient');

sc.controller('PasswordCtrl', function($scope, passwordStrengthComputations, badPasswords) {
sc.controller('PasswordCtrl', function($scope) {
$scope.loading = false;
$scope.passwordConfirmation = '';

// Remove default password requirements.
delete passwordStrengthComputations.aspects.minimumLength;
delete passwordStrengthComputations.aspects.uppercaseLetters;
delete passwordStrengthComputations.aspects.lowercaseLetters;
delete passwordStrengthComputations.aspects.numbers;
delete passwordStrengthComputations.aspects.duplicates;
delete passwordStrengthComputations.aspects.consecutive;
delete passwordStrengthComputations.aspects.dictionary;
delete passwordStrengthComputations.aspects.symbols;

// Enforce 8 character minimum.
passwordStrengthComputations.aspects.minLength = {
weight: 100,
strength: function(password){
var minLength = 8;
if(password.length < minLength/2) { return 25; }
if(password.length < minLength) { return 50; }
if(password.length < 2*minLength) { return 75; }
return 100;
$scope.passwordLevel = 'null';
$scope.passwordStrength = '';
$scope.rawScore = 0;

$scope.$watch('data.password', function(newValue, oldValue) {
if (newValue === '') {
$scope.passwordLevel = 'null';
$scope.passwordStrength = '';
$scope.rawScore = 0;
return;
}
};

passwordStrengthComputations.aspects.sameAsUsername = {
weight: 1,
strength: function(password) {
return $scope.data.username === password ? -1000 : 0;
var score = zxcvbn(newValue).score;
$scope.rawScore = score;
if (score < 2) {
$scope.passwordLevel = 'level1';
$scope.passwordStrength = 'WEAK';
return;
}
};

passwordStrengthComputations.aspects.dictionary = {
weight: 1,
strength: function(password) {
return badPasswords.contains(password) ? -1000 : 0;
if (score < 3) {
$scope.passwordLevel = 'level2';
$scope.passwordStrength = 'ALMOST';
return;
}
if (score < 4) {
$scope.passwordLevel = 'level3';
$scope.passwordStrength = 'GOOD';
return;
}
$scope.passwordLevel = 'level4';
$scope.passwordStrength = 'STRONG';
return;
});

$scope.passwordLevelClass = function () {
return $scope.passwordLevel;
};

$scope.checkPassword = function(){
$scope.errors.passwordErrors = [];
$scope.status.passwordValid = (passwordStrengthComputations.getStrength($scope.data.password) > 50);
$scope.status.passwordValid = ($scope.rawScore > 3);
$scope.checkConfirmPassword();
};

Expand All @@ -69,16 +70,6 @@ sc.controller('PasswordCtrl', function($scope, passwordStrengthComputations, bad
}
};

$scope.passwordStrength = function(){
if(!$scope.data.password) { return ''; }

var strength = passwordStrengthComputations.getStrength($scope.data.password);
if(strength < 25) { return 'WEAK'; }
if(strength < 50) { return 'ALMOST'; }
if(strength < 75) { return 'GOOD'; }
return 'STRONG';
};

// Validate the passwords are valid and matching.
function validateInput() {
// Remove any previous error messages.
Expand Down
Loading

0 comments on commit dc1380b

Please sign in to comment.