1212 @blur =" onBlur"
1313 >
1414 <div v-if =" field.indicator" class =" password-strength-indicator" :style =" meterStyle" />
15- <small v-if =" (field.suggestions || field.warning) && passwordFeedback" class =" password-feedback" >
16- <div v-if =" field.suggestions && passwordFeedback.suggestions.length" class =" password-suggestions" >
17- <strong >Suggestions</strong >
18- <ul class =" password-suggestions-ul" >
19- <li v-for =" suggestion in passwordFeedback.suggestions" :key =" suggestion" >{{ suggestion }}</li >
20- </ul >
21- </div >
22- <div v-if =" field.warning && passwordFeedback.warning" class =" password-warnings" >
23- <strong >Warning</strong >
24- <div >{{ passwordFeedback.warning }}</div >
25- </div >
26- </small >
2715 </div >
2816</template >
2917
3018<script >
31- import zxcvbn from ' zxcvbn'
3219import { abstractField } from ' @/mixins'
3320
3421export default {
3522 name: ' FieldPassword' ,
3623 mixins: [ abstractField ],
24+ data () {
25+ return {
26+ /** from PrimeVue */
27+ mediumRegex: new RegExp (' ^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})' ),
28+ strongRegex: new RegExp (' ^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.{8,})' )
29+ }
30+ },
3731 computed: {
38- shouldCheckPassword () {
39- return (this .field .indicator || this .field .suggestions || this .field .warning )
40- },
41- checkedPassword () {
42- if (! this .model [this .field .model ] || ! this .shouldCheckPassword ) return {}
43- return zxcvbn (this .model [this .field .model ])
44- },
4532 passwordStrength () {
46- return this .checkedPassword ? .score
47- },
48- passwordFeedback () {
49- return this .checkedPassword ? .feedback
33+ if (this .strongRegex .test (this .currentModelValue )) {
34+ return 3
35+ } else if (this .mediumRegex .test (this .currentModelValue )) {
36+ return 2
37+ } else if (this .currentModelValue .length ) {
38+ return 1
39+ }
40+ return 0
5041 },
5142 meterStyle () {
52- if (this .passwordStrength === 0 && this .model [this .field .model ].length > 0 ) {
53- return ' width:10%;background:red;'
54- }
5543 return {
56- 1 : ' width:25%;background:red;' ,
44+ 0 : ' ' ,
45+ 1 : ' width:15%;background:red;' ,
5746 2 : ' width:50%;background:orange;' ,
58- 3 : ' width:75%;background:green;' ,
59- 4 : ' width:100%;background:darkgreen;'
47+ 3 : ' width:100%;background:green;'
6048 }[this .passwordStrength ]
6149 }
6250 }
@@ -70,11 +58,4 @@ export default {
7058 width : 100% ;
7159 background : rgba (0 , 0 , 0 , 0.1 );
7260}
73-
74- .password - feedback {
75- margin- top: .5em ;
76- margin- bottom: 1em ;
77- display: grid;
78- grid- template- columns: 1fr 1fr ;
79- }
8061 </style >
0 commit comments