https://github.com/jdforsythe/angular-password-enforcement
https://github.com/jdforsythe/angular-password-enforcement
angular angular-directive angular-directives angular-validation angularjs password password-strength validation
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/jdforsythe/angular-password-enforcement
- Owner: jdforsythe
- License: mit
- Created: 2016-04-29T19:59:26.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-04-30T18:47:20.000Z (about 9 years ago)
- Last Synced: 2025-03-13T05:11:26.288Z (2 months ago)
- Topics: angular, angular-directive, angular-directives, angular-validation, angularjs, password, password-strength, validation
- Language: JavaScript
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
angular-password-enforcement
============================[](https://travis-ci.org/jdforsythe/angular-password-enforcement)
An Angular directive for validating password input against a set of rules
## Installation
```bash
$ bower install angular-password-enforcement
```## Setup
Include `angular-password-enforcement'` in your module's dependencies:
```js
angular.module('myApp', ['angular-password-enforcement']);
```## Configuration
By default, the directive includes a loose policy for the valid password (defaults are shown in the example below).
This is configurable based on your needs. Simple add a config block for your app:```js
angular.module('myApp', ['angular-password-enforcement'])
.config(function(validPasswordConfigProvider) {
validPasswordConfigProvider.setConfig({
minLength: 7,
maxLength: 30,
pattern: /^((?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*(_|[^\w])).{7,30})$/;
});
});
```It is recommended to also set a constant for the explanation of your password rules, that you can inject to use in all the views you'll have
password fields:```js
.constant('PASSWORD_RULES', '7-30 characters. At least 1 uppercase, 1 lowercase, 1 number, and 1 symbol. Symbols include: `~!@#$%^&*()-_=+[]{}\\|;:\'",.<>/?');app.controller('MyController', function(PASSWORD_RULES) {
var vm = this;
vm.passwordRules = PASSWORD_RULES;
});
```## Usage
Simply add the `valid-password` attribute to your `` field.
The directive attaches `ng-minlength` and `ng-maxlength` attributes to your form field. It also attaches an `invalidPassword` property to the
`$error` on your form field, so it can be used like any of the built-in validation directives.Note: This does *NOT FAIL* if the password field is empty. This is for cases where the user may be editing their profile and should
be allowed to leave the field empty. If you want to test for the empty field, you must add `ng-required="true"` to the input.The examples below assume the configuration block and constant are configured as shown above.
### Example with `ng-messages`
```html
Password is required
{{ vm.passwordRules }}
```
### Without `ng-messages`
```html
Routing number is required
{{ vm.passwordRules }}
```
## Tests
A round of tests is included. To run the tests, execute:
```bash
gulp test
```## Contributions
Contributions are always welcome. Please submit issues and pull requests.
## License
[MIT](LICENSE)