password_strength.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. define([
  2. '../core_module',
  3. ],
  4. function (coreModule) {
  5. 'use strict';
  6. coreModule.default.directive('passwordStrength', function() {
  7. var template = '<div class="password-strength small" ng-if="!loginMode" ng-class="strengthClass">' +
  8. '<em>{{strengthText}}</em>' +
  9. '</div>';
  10. return {
  11. template: template,
  12. scope: {
  13. password: "=",
  14. },
  15. link: function($scope) {
  16. $scope.strengthClass = '';
  17. function passwordChanged(newValue) {
  18. if (!newValue) {
  19. $scope.strengthText = "";
  20. $scope.strengthClass = "hidden";
  21. return;
  22. }
  23. if (newValue.length < 4) {
  24. $scope.strengthText = "strength: weak sauce.";
  25. $scope.strengthClass = "password-strength-bad";
  26. return;
  27. }
  28. if (newValue.length <= 8) {
  29. $scope.strengthText = "strength: you can do better.";
  30. $scope.strengthClass = "password-strength-ok";
  31. return;
  32. }
  33. $scope.strengthText = "strength: strong like a bull.";
  34. $scope.strengthClass = "password-strength-good";
  35. }
  36. $scope.$watch("password", passwordChanged);
  37. }
  38. };
  39. });
  40. });