Giter Site home page Giter Site logo

apertureless / vue-password-strength-meter Goto Github PK

View Code? Open in Web Editor NEW
562.0 15.0 67.0 2.38 MB

๐Ÿ” Password strength meter based on zxcvbn in vue.js

License: MIT License

JavaScript 61.86% HTML 0.67% Vue 37.47%
password-strength-meter zxcvbn vue vuejs vuejs2 password password-safety

vue-password-strength-meter's Introduction

๐Ÿ”“ vue-password-strength-meter

Build Status npm version vue2 license

ko-fi

Interactive password strength meter based on zxcvbn for vue.js

๐Ÿ”“

๐Ÿ“บ Demo

Demo here

๐Ÿ”ง Install

yarn add vue-password-strength-meter zxcvbn

๐Ÿ‘ˆ Usage

<template>
  <password v-model="password"/>
</template>

<script>
  import Password from 'vue-password-strength-meter'
  export default {
    components: { Password },
    data: () => ({
      password: null
    })
  }
</script>

๐Ÿ‘ˆ With events

<template>
  <password
    v-model="password"
    :toggle="true"
    @score="showScore"
    @feedback="showFeedback"
  />
</template>

<script>
  import Password from 'vue-password-strength-meter'
  export default {
    components: { Password },
    data: () => ({
      password: null
    }),
    methods: {
      showFeedback ({suggestions, warning}) {
        console.log('๐Ÿ™', suggestions)
        console.log('โš ', warning)
      },
      showScore (score) {
        console.log('๐Ÿ’ฏ', score)
      }
    }
  }
</script>

With custom input

<template>
  <div>
    <input type="password" v-model="password">
    <password v-model="password" :strength-meter-only="true"/>
  </div>
</template>

<script>
  import Password from 'vue-password-strength-meter'
  export default {
    components: { Password },
    data: () => ({
      password: null
    })
  }
</script>

Props

Prop Type Default Value Description
secureLength Number 7 password min length
badge Boolean true display password count badge
toggle Boolean false show button to toggle password visibility
showPassword Boolean false If you are not using the toggle button you can directly show / hide the password with this prop
defaultClass String Password__field input field class
disabledClass String Password__field--disabled disabled input field class
errorClass String Password__badge--error error class for password count badge
successClass String Password__badge--success success class for password count badge
strengthMeterClass String Password__strength-meter strength-meter class
strengthMeterFillClass String Password__strength-meter--fill strength-meter class for individual data fills
showStrengthMeter Boolean true Hide the Strength Meter if you want to implement your own
strengthMeterOnly Boolean false Hides the built-in input if you want to implement your own
labelHide String 'Hide Password' Label for the hide icon
labelShow String 'Show Password' Label for the show icon
userInputs Array empty array Array of strings that zxcvbn will treat as an extra dictionary
referenceValue String 'input' Prop to change the ref of the input. This way you can have the input outside of the component.

Events

Show / Hide Password

  • @show will be emitted if showing the password
  • @hide will be emitted if hiding the password
  • @score will return the zxcvbn score (Integer from 0-4) [โ„น] (https://github.com/dropbox/zxcvbn#usage)
  • @feedback will return an zxcvbn feedback object with suggestion and warning

๐Ÿ’… Customizing

You can customize the styling of the input field, badge and strength-meter by passing your own css classes to defaultClass, strengthMeterClass etc.

Build Setup

# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

# build for production with minification
npm run build

# run unit tests
npm run unit

# run all tests
npm test

For detailed explanation on how things work, checkout the guide and docs for vue-loader.

Support

Buy Me A Coffee

vue-password-strength-meter's People

Contributors

a21ns1g4ts avatar aarongerig avatar apertureless avatar champi-dev avatar chocanto avatar greenkeeper[bot] avatar hallowcard13 avatar humanrupert avatar jokerqyou avatar khamer avatar martinherweg avatar razorness avatar stefanzweifel avatar tksumanth1994 avatar xaviervallot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-password-strength-meter's Issues

What is "/Users/jjuszczak/Projekte/Privat/"

Expected Behavior

No crash the Nuxt.

Actual Behavior

Show really strange error.

[Vue warn]: Error in beforeCreate hook: "ReferenceError: document is not defined"

found in

---> <Password> at /Users/jjuszczak/Projekte/Privat/vue-password-strength-meter/src/components/PasswordStrengthMeter.vue
       <ElFormItem> at packages/form/src/form-item.vue
         <ElForm> at packages/form/src/form.vue
           <SignUpForm> at pages/signup.vue
             <Nuxt>
               <ElMain> at packages/main/src/main.vue
                 <ElContainer> at packages/container/src/main.vue
                   <Blank> at layouts/blank.vue
                     <Root>

My user account is sangdth and I have no idea is that user jjuszczak

Environment

  • OS: Mac OS 10.14.3
  • NPM version: 6.8.0
  • vue.js version: Nuxtjs 2.4
  • vue-password-strength-meter version: 1.4.1

Add documentation

I guess it is time to add some proper documentation and examples of the usage.
Feel free to add suggestions if you want specific examples.

Usage Examples:

  • With badge / Without badge
  • With toggle enabled
  • Custom toggle button
  • Without strength-meter
  • Custom strength-meter
  • Form example
  • Prevent submission of the form if the score is below a certain level
  • Custom input element if #19 gets merged

How to get value out?

Expected Behavior

input events emitted to parent

Actual Behavior

No event emitted so unable to observe password value

From Vue.js Docs:

So for a component to work with v-model, it must:
accept a value prop
emit an input event with the new value

Environment

  • OS: Mac
  • NPM version: 3.x
  • vue.js version: 2.x
  • vue-password-strength-meter version: 0.1.2

Pressing `enter` key on input toggles the password visibility

Pre-requisite

toggle prop must be set to true

Expected Behavior

User is typing a password and presses enter key, the input should not toggle the password visibility

Actual Behavior

User is typing a password and presses enter key, the input is toggling the password visibility

This is an issue since whenever we want to submit the form, instead of submitting it, it just toggle the type.

Environment

  • NPM version: 6.0.1
  • vue.js version: 2.5.16
  • vue-password-strength-meter version: 1.3.0

Support for zxcvbn user_inputs prop?

Unless I am mistaken there is currently no support for the zxcvbn user_inputs prop? I would love to see it supported, as currently if a user tries to register by entering an email, and then the same email in the password field, the password gets a high score.

CSS .is-success is conflicting with bulma framework

Expected Behavior

Styles within this component will not override styles in base framework

Actual Behavior

The ".is-success" css in ./src/components/PasswordStrengthMeter.vue at line 306 is overriding the base styles in the bulma css framework.

Could this style be scoped? Or prefixed with Password__strength-meter ?

Environment

  • OS: Linux
  • NPM version: 5.3.0
  • vue.js version: 2.5.2
  • vue-password-strength-meter version: 1.1.0

Add $attrs directly to input field

It might be a good idea to bind the $attrs directly to the input field.
This way we can get rid of some of the props and users could add aria labels and other attributes directly to the <Password/> element.

showPassword not working

Expected Behaviour

When I set the showPassword prop to true, the input type is not changing from "password" to "text".

Actual Behavior

When I set the showPassword prop to true, the input type is always "password".

Environment

  • OS: macOS Sierra 20.12.6
  • NPM version: 5.6.0
  • vue.js version: 2.5.13
  • vue-password-strength-meter version: 1.1.1

strength-meter-only - Empty payload on emitted event

I created a Vuetify text-field a my password input:

<v-text-field
    name="password"
    id="password"
    v-model="password"
    type="password"
    :rules="passwordRules"
    required
>

Appended the following
<password v-model="password" :strength-meter-only="true"/>

Expected Behavior

The meter fill should be filled with the score

Actual Behavior

The meter is not updated

I did some digging

The event emitted by the component has an empty payload, caused by:

watch: {
  value (newValue) {
    if (this.strengthMeterOnly) {
      this.emitValue(newValue)
    }
  }
}

While emitValue expects two arguments

methods: {
  emitValue (type, value) {
    this.$emit(type, value)
    this.password = value
  }
}

Therefore setting this.password to undefined

Environment

  • OS: Macos 10.13.6
  • NPM version: 6.5.0
  • vue.js version: 2.5.21
  • vue-password-strength-meter version: 1.4.0

`vue-cli` support (feature request)

Expected Behavior

$ vue add vue-password-strength-meter zxcvbn
Installed!

All necessary dependencies would be added to the package.json according to https://cli.vuejs.org/guide/plugins-and-presets.html#plugins such as (https://github.com/vuetifyjs/vue-cli-plugin-vuetify, router or vuex)

Actual Behavior

$ vue add vue-password-strength-meter zxcvbn

๐Ÿ“ฆ  Installing vue-cli-plugin-vue-password-strength-meter...

npm ERR! code E404
npm ERR! 404 Not Found: vue-cli-plugin-vue-password-strength-meter@latest

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/Clark/.npm/_logs/2018-11-14T15_59_59_465Z-debug.log
 ERROR  command failed: npm install --loglevel error -D vue-cli-plugin-vue-password-strength-meter

Environment

  • OS: Darwin
  • NPM version: 6.4.1
  • vue.js version: 2.5.7
  • vue-cli version: 3.0.3
  • vue-password-strength-meter version: @latest

๐Ÿ‘€ ๐Ÿ™ˆ Show / Hide Password Button

Description

It would be nice to have a small icon / indicator to show & hide your password.
Would be useful on mobile and for single-password signups, where you don't want to add a verification password field.

Todo-list

  • Add showPassword prop to toggle password show and hide
  • Add toggle prop to toggle internal show / hide button
  • Add SVG Icon for password show and password hide
  • Add slot for icon / button so people can customize it
  • Emit showPassword and hidePassword event

Add options for custom hide/show labels

It would be awesome to be able to insert custom texts for the "Hide password" and "Show password" labels.

Im using this component on a danish website, and it would be nice to be able to translate the labels without editing the source code. :)

Any plans to support I18N for password hints in some way?

Love this code and am using it in a new project which will be available in several languages.

All works perfectly, but an extra "nice-to-have" feature would be if I could also offer the password hints in other languages - perhaps by allowing me to define translation files as json props or something?

Responsive behaviour breaks

Expected Behavior

On narrower containers (and viewports), the strength meter should fluidly resize (become smaller in width by keeping its 5 evenly sized sections).

Actual Behavior

Meter's mid block is the only part that goes narrower and after X width actually becomes wider again, eating away at other blocks.

How to reproduce

Go to this plugin's demo page, slap a

<meta name="viewport" content="width=device-width,initial-scale=1.0">

into the document's head and then resize the viewport or restrict the parent via CSS:

#app {
  max-width: 22rem;
}

Environment

  • OS: OSX (although doubt it's OS-related)
  • NPM version: Should not matter
  • vue.js version: 2.5.16
  • vue-password-strength-meter version: 1.3.2

Make it possible to set id attribute for input element

Expected Behavior

Having an id prop to pass down to the input[type="password] element.

Actual Behavior

No such property available (from the looks of it in the docs)

Maybe such a thing is possible and I merely didn't see it? This is required to use labels with the for attribute. Putting id on the password component itself, will result in both the wrapper AND the input to have the same ID, which is bad.

When v-model is populated my a generate button it does not change the password strength

Expected Behavior

Shows the same behavior when it is filled manually

Actual Behavior

it does not show the password strength and sometimes it does not update the password on the input.

I forked a sandbox from someone with an older version and was able to replicate the behavior
https://codesandbox.io/s/vue-password-strength-meter-forked-x0ou4?fontsize=14&hidenavigation=1&theme=dark

Environment

  • OS: macOS (Catalina)
  • NPM version: 12.8.4
  • vue.js version: 4.5.6
  • vue-password-strength-meter version: 1.7.2

[Vue warn]: Error in getter for watcher "passwordStrength": "TypeError: (0 , o.default) is not a function"

All scripts iImported via cdn:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
<script src="https://unpkg.com/[email protected]/lodash.js"></script>
<script src="https://unpkg.com/[email protected]/dist/vuelidate.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/validators.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue-password-strength-meter.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/zxcvbn.js"></script>

Vue app:

<div id="v-my-own-app"></div>

<script>
	Vue.use(window.vuelidate.default);
	
	Vue.component('password', Password);

	var app = new Vue({
		el: '#v-my-own-app',
		components: {
			'a-custom-component': ACustomComponent,
		},
		data: {
		},
	})        
</script>

Vue component:

const { required, email, minLength, sameAs, not } = window.validators;

var ACustomComponent = Vue.component("ACustomComponent", {
  template: `
      ...
     <password v-model="password" :strength-meter-only="true"/>
      ...
`,

  props: {
    myProp: {
      required: true,
    },
  },
  data() {
    return {
      username: "",
      password: "",
    };
  },
  validations: {
    username: {
      required,
      minLength: minLength(5),
    },
    password: {
      required,
      minLength: minLength(8),
      isNotSameAsUsername: not(sameAs("username")),
    },
  },

Expected Behavior

Expected to work the same way as imported via webpack/cli.

Actual Behavior

Error on page load:

[Vue warn]: Error in getter for watcher "passwordStrength": "TypeError: (0 , o.default) is not a function"

found in

---> <VuePasswordStrengthMeter>

vue.js:1897 TypeError: (0 , o.default) is not a function
    at VueComponent.passwordStrength (vue-password-strength-meter.js:1)
    at Watcher.get (vue.js:4478)

[Vue warn]: Error in callback for watcher "passwordStrength": "TypeError: (0 , o.default) is not a function"

found in

---> <VuePasswordStrengthMeter>

TypeError: (0 , o.default) is not a function
    at VueComponent.passwordStrength (vue-password-strength-meter.js:1)
    at Watcher.run (vue.js:4567)

Environment

  • OS: OSX 10.14.x
  • NPM version: None
  • Browser Firefox and Chrome
  • vue.js version: 2.6.11
  • vue-password-strength-meter version: 1.7.2

Toggle icon blocks LastPass auto-fill icon

Expected Behavior

Should be able to auto-fill password by clicking on LastPass icon at right side of input box. This refers to the LastPass's Chrome extension.

Actual Behavior

Toggle icon displays over the LastPass icon, and is not clickable. There probably needs to be more right margin added to move the toggle icon to the left. Any other icon options used by vue-password-strength-meter should also be moved further to the left.

Screen Shot 2020-11-05 at 3 15 31 PM

Environment

  • OS: Mac/Windows
  • NPM version: 6.14.8
  • vue.js version: 2.6.11
  • vue-password-strength-meter version: 1.7.1

Style not rendering whem the component is extended

Expected Behavior

When extended, the component should pass the styles for the one who's extending it.

Actual Behavior

The component is loosing the css when extended, rendering the html and the tags, but not the style.

Environment

  • OS: Ubuntu 18.04 LTS
  • NPM version: 5.7.1
  • vue.js version: 2.5.16
  • vue-password-strength-meter version: 1.2.1

Blur event and input class customization

Expected Behavior

To be able to customize input class (for example red border)
To be able to catch the blur event

Actual Behavior

Nothing happen when using directives like :class and @blur

<password
          placeholder=""
          :toggle="true"
          :badge="false"
          v-model="userData.password"
          defaultClass="form-control"
          :class="{'is-invalid': $v.userData.password.$error}"
          @blur="$v.userData.password.$touch()" />

Environment

  • OS: Ubuntu + Chrome
  • NPM version: 3.5.2
  • vue.js version: 2.5.15
  • vue-password-strength-meter version: 1.3.2

Feedback event should be emitted more aggressively

Expected Behavior

I tried to type 123456 as a password, since 12345 is a top-10 used password, I expected to see the warning right after the password changed to 12345 as I type.

Actual Behavior

  • I tried to type 123456 as password.
  • When I typed 1 as password, I got strength 1, with suggestions: [ "Add another word or two. Uncommon words are better." ] and no warnings.
  • No feedback event got emitted after that, I typed all six digits.
  • I pressed backspace key, deleting 6, still no event.
  • I then typed 5, so the password is now 123455, stength changed to 2, feedback event emitted with suggestions [ "Add another word or two. Uncommon words are better." ] and warning This is a very common password.
  • I deleted the last 5, strength dropped to 1, feedback emitted with suggestions [ "Add another word or two. Uncommon words are better." ] and warning This is a top-10 common password.

Related code is here, the feedback event is only emitted when the strength of password is changed.

But I think users are expecting to see realtime suggestions / warnings, which means we should be emitting feedback event when password value changed. As you can see from my steps above, the first time the password changed to 12345 as I type, no feedback was generated; But the second time I got a top-10 warning. This feels inconsistent and is very confusing.

Environment

  • OS: OS is not relevant
  • NPM version: 6.14.5
  • vue.js version: 2.6.12
  • vue-password-strength-meter version: 1.7.2

Reverse "Show" / "Hide" labels

Expected Behavior

When i click the icon with label: "Hide password" i expect it to hide the password

Actual Behavior

It's actually opposite, it shows password when i click the icon with title "Hide password" and vice versa.

Solution

Reverse the "Hide"/"Show" title/labels

Vue3 support

Hi there !

Thank you for this awesome library.

I tried to use it in a Vue3 project and it didn't work. The password value seems to keep only one character.

After investigating a bit I found these references about breaking changes in Vue3

If anyone else is trying to make this component compatible with Vue3 you need to make the following changes in src/components/PasswordStrengthMeter.vue

line 14:

        :value="modelValue"

line 62:

     emits: ['input', 'blur', 'focus', 'score', 'hide', 'show', 'update:modelValue', 'feedback'],

line 68:

      modelValue: {
        type: String
      },

line 232:

      emitValue (type, value) {
        if (type == 'input') {
          this.$emit('update:modelValue', value) // Changed in Vue 3
        }
        else {
          this.$emit(type, value)
        }
        this.password = value
      }

line 294:

    watch: {
      modelValue (newValue) {

This makes it work on my environment with [email protected] .

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.