12
12
@blur =" onBlur"
13
13
>
14
14
<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 >
27
15
</div >
28
16
</template >
29
17
30
18
<script >
31
- import zxcvbn from ' zxcvbn'
32
19
import { abstractField } from ' @/mixins'
33
20
34
21
export default {
35
22
name: ' FieldPassword' ,
36
23
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
+ },
37
31
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
- },
45
32
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
50
41
},
51
42
meterStyle () {
52
- if (this .passwordStrength === 0 && this .model [this .field .model ].length > 0 ) {
53
- return ' width:10%;background:red;'
54
- }
55
43
return {
56
- 1 : ' width:25%;background:red;' ,
44
+ 0 : ' ' ,
45
+ 1 : ' width:15%;background:red;' ,
57
46
2 : ' width:50%;background:orange;' ,
58
- 3 : ' width:75%;background:green;' ,
59
- 4 : ' width:100%;background:darkgreen;'
47
+ 3 : ' width:100%;background:green;'
60
48
}[this .passwordStrength ]
61
49
}
62
50
}
@@ -70,11 +58,4 @@ export default {
70
58
width : 100% ;
71
59
background : rgba (0 , 0 , 0 , 0.1 );
72
60
}
73
-
74
- .password - feedback {
75
- margin- top: .5em ;
76
- margin- bottom: 1em ;
77
- display: grid;
78
- grid- template- columns: 1fr 1fr ;
79
- }
80
61
</style >
0 commit comments