Giter VIP home page Giter VIP logo

ng2-password-strength-bar's Introduction

ng2-password-strength-bar

Build Status npm version

This an Angular 2 implementation of AngularJS Directive to test the strength of a password.

Try it live!

Angular 9 Support

If you are using Angular 9+ you will need to use ng9-password-strength-bar.

The only configuration differences between the ng2 and ng9 versions are these name changes:

  • ng2-password-strength-bar --> ng9-password-strength-bar
  • PasswordStrengthBarModule --> Ng9PasswordStrengthBarModule

Install in your project

npm install ng2-password-strength-bar --save

Version Update Note

If you upgrade from v1.0.x to v1.1.x (or greater) you will need to change the PasswordStrengthBar import. There are two options:

  1. Change to PasswordStrengthBarModule and add this to the imports section of the @NgModule metadata instead of the declarations (shown below), or
  2. Change to PasswordStrengthBarComponent and update the name in the declarations section to match.

Using the Component

Add Component to Module imports

import { PasswordStrengthBarModule } from 'ng2-password-strength-bar';
//...
@NgModule({
 //...
   declarations: [
        AppComponent,
        //...
    ],
    imports: [
      BrowserModule,
      FormsModule,
      PasswordStrengthBarModule,
      //...
 //...
})
export class AppModule {}

Add Component to your Application

@Component({
    selector: 'my-app',
    template: `
  <h3>Angular 2 Password Strength Bar</h3>
    <div>
       <form name="myForm" novalidate>
            <input type="password" class="form-control" id="password" name="password" placeholder="Enter password"
                 [(ngModel)]="account.password" #password="ngModel"
                 minlength="5" maxlength="50" required>
            <ng2-password-strength-bar
                [passwordToCheck]="account.password"
                [barLabel]="barLabel"
                [barColors]="myColors">
            </ng2-password-strength-bar>
        </form>
    </div>
  `,
})
export class App {
    public account = {
        password: <string>null
    };
    public barLabel: string = "Password strength:";
    public myColors = ['#DD2C00', '#FF6D00', '#FFD600', '#AEEA00', '#00C853'];
    // ...
}

Parameters

<ng2-password-strength-bar
  [passwordToCheck]="account.password"
  [barLabel]="barLabel"
  [barColors]="myColors"
  [baseColor]="baseColor"
  [strengthLabels]="strengthLabels"
  (onStrengthChanged)="strengthChanged($event)">
</ng2-password-strength-bar>

Input Parameters

passwordToCheck (type: string)

  • The variable containing the password to check.

barLabel (type: string)

  • The variable containing the label displayed to the left of the bar.

barColors (type: Array<string>, optional)

(New in v1.2.0)

  • The variable can be used to define custom bar colors.
  • This must be an Array of 5 strings.
  • Lowest security level picks colors[0], ..., the highest picks colors[4].
  • If not specified, the default is: ['#F00', '#F90', '#FF0', '#9F0', '#0F0']

baseColor (type: string, optional)

(New in v1.2.1)

  • The variable can be used to define the color of bars when no strength is applied (i.e. when there is no password text).
  • If not specified, the default is: '#DDD'.
    For example:
public baseColor = '#FFF';

strengthLabels (type: Array<string>, optional)

(New in v1.2.1)

  • The variable can be used to define a strength label that will be appended to the colored bars.
  • This must be an Array of 5 strings.
    For example:
public strengthLabels = ['(Useless)', '(Weak)', '(Normal)', '(Strong)', '(Great!)'];

Output Parameters

onStrengthChanged(strength: number) optional

  • Event triggered when the password changes.
  • Takes a single number parameter (the new password strength with value 0 to 4).
strengthChanged(strength: number) {
  this.strength = strength;
}

Run the example application locally

  • git clone https://github.com/rnadler/ng2-password-strength-bar.git
  • cd ng2-password-strength-bar
  • npm install
  • npm start # Browser should open automatically on http://localhost:3000

Run the tests locally

  • Same as above, except for the last step do:
  • npm run test-once # Defaults to a Firefox browser

License

MIT

ng2-password-strength-bar's People

Contributors

bogdanbaghiu avatar btxtiger avatar evansmwendwa avatar feeloor avatar johnfedoruk avatar karolmie1 avatar rnadler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ng2-password-strength-bar's Issues

(index):25 Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:49339/node_modules/ng2-password-strength-bar/lib/passwordStrengthBar.module

i add the package on my system.config.js

System.config ({
path: {
'npm:': 'node_modules/'
},
map: {
'app': '/app'

(...)Other packages

'ng2-password-strength-bar': 'npm:ng2-password-strength-bar/index.js',

},
}
and this is the problem

(index):25 Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:49339/node_modules/ng2-password-strength-bar/lib/passwordStrengthBar.module
Error: XHR error (404 Not Found) loading http://localhost:49339/node_modules/ng2-password-strength-bar/lib/passwordStrengthBar.module
at XMLHttpRequest.wrapFn [as __zone_symbol___onreadystatechange] (http://localhost:49339/node_modules/zone.js/dist/zone.js:1070:39)
at ZoneDelegate.invokeTask (http://localhost:49339/node_modules/zone.js/dist/zone.js:424:31)
at Zone.runTask (http://localhost:49339/node_modules/zone.js/dist/zone.js:191:47)
at ZoneTask.invokeTask [as invoke] (http://localhost:49339/node_modules/zone.js/dist/zone.js:499:34)
at invokeTask (http://localhost:49339/node_modules/zone.js/dist/zone.js:1349:10)
at XMLHttpRequest.globalZoneAwareCallback (http://localhost:49339/node_modules/zone.js/dist/zone.js:1358:13)
Error loading http://localhost:49339/node_modules/ng2-password-strength-bar/lib/passwordStrengthBar.module as "./lib/passwordStrengthBar.module" from http://localhost:49339/node_modules/ng2-password-strength-bar/index.js
at XMLHttpRequest.wrapFn [as __zone_symbol___onreadystatechange] (http://localhost:49339/node_modules/zone.js/dist/zone.js:1070:39)
at ZoneDelegate.invokeTask (http://localhost:49339/node_modules/zone.js/dist/zone.js:424:31)
at Zone.runTask (http://localhost:49339/node_modules/zone.js/dist/zone.js:191:47)
at ZoneTask.invokeTask [as invoke] (http://localhost:49339/node_modules/zone.js/dist/zone.js:499:34)
at invokeTask (http://localhost:49339/node_modules/zone.js/dist/zone.js:1349:10)
at XMLHttpRequest.globalZoneAwareCallback (http://localhost:49339/node_modules/zone.js/dist/zone.js:1358:13)
Error loading http://localhost:49339/node_modules/ng2-password-strength-bar/lib/passwordStrengthBar.module as "./lib/passwordStrengthBar.module" from http://localhost:49339/node_modules/ng2-password-strength-bar/index.

Get level of security as integer

Maybe Feature Request:

Is ist already possible to retrieve the security-level as integer, so I can forbid passwords with a lower security-level than "3" ?

How can I configure the rules ?

Hello,

I would like to have the possibility to configure the rules, like changing the minimum length of a password to be considered strong. Is this possible ?

Cheers

NPM Install Fails with "Class 'Subject<T>' incorrectly extends base class 'Observable<T>'"

Local Versions

  • npm: 4.0.3
  • angular/cli: 1.3.2
  • node: 7.4.0
  • os: linux x64
  • angular/common: 2.4.10
  • angular/compiler: 2.4.10
  • angular/compiler-cli: 2.4.10
  • angular/core: 2.4.10
  • angular/forms: 2.4.10
  • angular/http: 2.4.10
  • angular/platform-browser: 2.4.10
  • angular/platform-browser-dynamic: 2.4.10
  • angular/platform-server: 2.4.10
  • angular/router: 3.4.10

NPM stderr

$ npm install > /dev/null
npm WARN prepublish-on-install As of npm@5, prepublish scripts will run only for npm publish.
npm WARN prepublish-on-install (In npm@4 and previous versions, it also runs for npm install.)
npm WARN prepublish-on-install See the deprecation note in npm help scripts for more information.
Error at /var/www/wiser/ng2-password-strength-bar/node_modules/rxjs/Subject.d.ts:16:22: Class 'Subject' incorrectly extends base class 'Observable'.
Types of property 'lift' are incompatible.
Type '(operator: Operator<T, R>) => Observable' is not assignable to type '(operator: Operator<T, R>) => Observable'.
Type 'Observable' is not assignable to type 'Observable'.
Type 'T' is not assignable to type 'R'.

npm ERR! Linux 4.4.0-79-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "ngc-build"
npm ERR! node v7.4.0
npm ERR! npm v4.0.5
npm ERR! code ELIFECYCLE
npm ERR! [email protected] ngc-build: rm -rf lib && rm -rf "src/node_modules" && "node_modules/.bin/ngc" -p tsconfig-aot.json
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] ngc-build script 'rm -rf lib && rm -rf "src/node_modules" && "node_modules/.bin/ngc" -p tsconfig-aot.json'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the ng2-password-strength-bar package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! rm -rf lib && rm -rf "src/node_modules" && "node_modules/.bin/ngc" -p tsconfig-aot.json
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs ng2-password-strength-bar
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls ng2-password-strength-bar
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /var/www/wiser/ng2-password-strength-bar/npm-debug.log

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! Linux 4.4.0-79-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v7.4.0
npm ERR! npm v4.0.5
npm ERR! code ELIFECYCLE
npm ERR! [email protected] prepublish: npm run ngc-build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] prepublish script 'npm run ngc-build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the ng2-password-strength-bar package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! npm run ngc-build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs ng2-password-strength-bar
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls ng2-password-strength-bar
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /var/www/wiser/ng2-password-strength-bar/npm-debug.log

Move angular dependencies to dev dependencies.

When I'm using this module npm forces me to download version of angular that I didn't want to use.
Only angular core should be main dependency, and version 2.whatever would be enough.
Other angular dependencies are used only for tests, and should be treated as dev deps.

Not compatible with Anuglar 9.1 and Ivy

When upgrading from Angular 8 to 9.1 the compiler give that error.

This likely means that the library (ngx-store) which declares WebStorageModule has not been processed correctly by ngcc, or is not compatible with Angular Ivy. Check if a newer version of the library is available, and update if so. Also consider checking with the library's authors to see if the library is expected to be compatible with Ivy.

Any idea?

PasswordStrengthBarModule' is not exported by node_modules\ng2-password-strength-bar\index.js

After compiling my app with AOT I'm going through the process of tree-shakin my bundle. But when I start node_modules/.bin/rollup -c rollup-config.js after a few seconds the systems quits with the following error message:

� 'PasswordStrengthBarModule' is not exported by node_modules\ng2-password-strength-bar\index.js
https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module
src\app\app.module.js (58:9)

Any ideas how to fix this?
Thanks in advance.
OASE

FeatureRequest: Define custom colors

I'd like to adjust the bar colors to my page theme.
An option could be to pass an array to the directive to overwrite the defaults:

<ng2-password-strength-bar 
    [colors]="myColors" 
    [passwordToCheck]="formData.passwd" 
    barLabel="Security: ">
</ng2-password-strength-bar>
export class myComponent {
   public myColors = [‘#F00’, ‘#F90’, ‘#FF0’, ‘#9F0’, ‘#0F0’];
}

"Issue"

Hey,

first of all I just want to say that this is very nice component!

This is not an issue, it's more suggestion that you could add some @output so we could use password strength for form validations in future version.

Thanks! 👍 :)

How to adjust points width

Hi,

How can I adjust the points width?

I have tried the following code with no luck:

.strengthBar[_ngcontent-c2] .point[_ngcontent-c2] { width: 40px !important; }

Change detection OnPush maybe?

All changes are done on Input change, so OnPush strategy would be viable, and would provide that sweet sweet performance boost.

changeDetection: ChangeDetectionStrategy.OnPush`

How to implement this in Angular's reactive form ?

Hello,

I'm relatively new to Angular 2. So when I implemented the validations, I used reactive forms instead of going with ngModel.
In the example you only specify with ngModel. Can this be implemented in reactive form ?

Thanks.

Move Project to Angular 5

Maybe this project should be moved to Angular 5, in order to have angular-cli and webpack as module bundler. This would be a lot more handy and simpler. Currently every change in src/ needs a restart, because even if systemjs detects the change and reloads, tsc does not recompile.

Erro while "ng build --prod --aot"

ERROR in Error encountered resolving symbol values statically. Calling function 'makeParamDecorator', function c
alls are not supported. Consider replacing the function or lambda with a reference to an exported function, reso
lving symbol Injectable in D:/Praveen data/angular/Merchat Project/node_modules/ng2-password-strength-bar/node_m
odules/@angular/core/src/di/metadata.d.ts, resolving symbol OpaqueToken in D:/Praveen data/angular/Merchat Proje
ct/node_modules/ng2-password-strength-bar/node_modules/@angular/core/src/di/opaque_token.d.ts, resolving symbol
OpaqueToken in D:/Praveen data/angular/Merchat Project/node_modules/ng2-password-strength-bar/node_modules/@angu
lar/core/src/di/opaque_token.d.ts

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'D:\Praveen data\angular\Mercha
t Project\src'
@ ./src/main.ts 5:0-74
@ multi ./src/main.ts

Uncaught Error: Unexpected value 'PasswordStrengthBar' declared by the module 'AppModule'

Versions.
angular-cli: 1.0.0-beta.15
node: 5.0.0
os: win32 x64

I am trying to use 'ng2-password-strength-bar' in my application.
When i try to import it in my app.module.ts file:

import { PasswordStrengthBar } from "ng2-password-strength-bar";

@NgModule({
declarations: [
AppComponent,
PasswordStrengthBar]

it is giving me following runtime error (no compile time error):

Uncaught Error: Unexpected value 'PasswordStrengthBar' declared by the module 'AppModule'
at http://localhost:4200/main.bundle.js:28457:31
at Array.forEach (native)
at CompileMetadataResolver.getNgModuleMetadata (http://localhost:4200/main.bundle.js:28444:49)
at RuntimeCompiler._compileComponents (http://localhost:4200/main.bundle.js:44967:47)
at RuntimeCompiler.compileModuleAndComponents (http://localhost:4200/main.bundle.js:44905:37)
at RuntimeCompiler.compileModuleAsync (http://localhost:4200/main.bundle.js:44896:21)
at PlatformRef
.bootstrapModuleWithZone (http://localhost:4200/main.bundle.js:30834:25)
at PlatformRef
.bootstrapModule (http://localhost:4200/main.bundle.js:30816:21)
at Object. (http://localhost:4200/main.bundle.js:62874:124)
at webpack_require (http://localhost:4200/inline.js:53:30)

ERROR TypeError: Cannot read property 'currentValue' of undefined

Hello.

I am trying to change the barLabel tag based on the language. When I change from English to Spanish I should change "Password consistent" to "Password consistency" but it gives me the following error.
I have observed that it looks if the currentValue of the password is
var password = changes['passwordToCheck'].currentValue;
It is seen that the passwordToCheck is undefined and cannot read currentValue.

EditUserPage.html:22 ERROR TypeError: Cannot read property 'currentValue' of undefined at PasswordStrengthBarComponent.push../node_modules/ng2-password-strength-bar/lib/passwordStrengthBar.component.js.PasswordStrengthBarComponent.ngOnChanges (passwordStrengthBar.component.js:77) at checkAndUpdateDirectiveInline (core.js:27784) at checkAndUpdateNodeInline (core.js:38472) at checkAndUpdateNode (core.js:38411) at debugCheckAndUpdateNode (core.js:39433) at debugCheckDirectivesFn (core.js:39376) at Object.eval [as updateDirectives] (EditUserPage.html:23) at Object.debugUpdateDirectives [as updateDirectives] (core.js:39364) at checkAndUpdateView (core.js:38376) at callViewAction (core.js:38742)

Access the strength value?

I have the password strength bar working great, thanks. However I can't seem to see anywhere how I can use the strength value to do things like enable a Submit button. How can you access - possibly with an isValid sort of property or anything really?

Thanks!
Craig

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.