Skip to content

Instantly share code, notes, and snippets.

@alejandrobernardis
Last active December 19, 2015 16:58
Show Gist options
  • Select an option

  • Save alejandrobernardis/5987311 to your computer and use it in GitHub Desktop.

Select an option

Save alejandrobernardis/5987311 to your computer and use it in GitHub Desktop.
Check Password Complexity (#angularjs, #coffeescript)
<div class="check-password-complexity" ng:show="password">
<small class="text-muted">La contrase&ntilde;a es:
<strong class="text-{{complexity}}"
ng:bind-html-unsafe="description"></strong>
</small>
<div class="progress">
<div class="progress-bar progress-bar-{{complexity}}"
style="width: {{percentage}}%"></div>
</div>
</div>
<html lang="es" xmlns:ng="http://angularjs.org" ng:app="SmileComponents">
...
<input type="password" id="password" placeholder="Contrase&ntilde;a" ng:model="form_data.password">
<check-password-complexity password="form_data.password"></check-password-complexity>
...
'use strict';
app = angular.module('SmileComponents', [])
app
.directive 'checkPasswordComplexity',
()->
restrict: 'E'
templateUrl: '/static/template/components/check-password-complexity.html'
transclude: true
scope:
complexity: '@'
percentage: '@'
description: '@'
password: '='
link:
(scope)->
scope.$watch 'password',
(password, old)->
score = 0;
if password and password.length >= 6
5 < password.length < 13 and score += 15
12 < password.length < 17 and score += 35
16 < password.length and score += 55
password.match(/(.*[0-9].*[0-9].*[0-9])/) and score += 5
password.match(/(.*[!@#$%^&*?_~+=-].*[!@#$%^&*?_~+=-])/) and score += 5
password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/) and score += 10
password.match(/([a-zA-Z])/) and password.match(/([0-9])/) and score += 15
password.match(/([!@#$%^&*?_~+=-])/) and password.match(/([0-9])/) and score += 15
password.match(/([!@#$%^&*?_~+=-])/) and password.match(/([a-zA-Z])/) and score += 15
(password.match(/^\w+$/) or password.match(/^\d+$/)) and score -= 10
0 > score and score = 0
100 < score and score = 100
if score < 35
scope.complexity = 'danger'
scope.description = 'd&eacute;bil'
else if 34 < score < 50
scope.complexity = 'warning'
scope.description = 'aceptable'
else if 49 < score < 75
scope.complexity = 'info'
scope.description = 'segura'
else if 74 < score
scope.complexity = 'success'
scope.description = 'muy segura'
else
scope.complexity = 'danger'
scope.description = 'menor a 6 caracteres'
scope.percentage = score
return
return
@_smile_components = app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment