Skip to content

Commit 2cd8f19

Browse files
committed
refactor!: remove zxcvbn as password strength meter
BREAKING CHANGE
1 parent 2d300de commit 2cd8f19

File tree

2 files changed

+19
-40
lines changed

2 files changed

+19
-40
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
"files": [
2424
"dist"
2525
],
26-
"dependencies": {
27-
"zxcvbn": "^4.4.2"
28-
},
26+
"dependencies": {},
2927
"devDependencies": {
3028
"@stylistic/eslint-plugin": "^2.8.0",
3129
"@vitejs/plugin-vue": "^5.1.3",

src/fields/input/FieldPassword.vue

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,51 +12,39 @@
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'
3219
import { abstractField } from '@/mixins'
3320
3421
export 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

Comments
 (0)