Add live password strength indicators

This commit is contained in:
sas.fajri
2026-05-08 11:37:04 +07:00
parent 873c47760d
commit 1040655ea8

View File

@@ -35,8 +35,19 @@
type="password" type="password"
hint="Minimal 8 karakter, wajib huruf besar, huruf kecil, angka, dan simbol" hint="Minimal 8 karakter, wajib huruf besar, huruf kecil, angka, dan simbol"
persistent-hint persistent-hint
:success="passwordReady"
:error="passwordTouched && !passwordReady"
:error-messages="passwordTouched && !passwordReady ? ['Password belum memenuhi aturan'] : []"
@blur="passwordTouched = true"
v-model="password" v-model="password"
></v-text-field> ></v-text-field>
<div class="caption mt-1">
<span :class="passwordChecks.length ? 'green--text' : 'red--text'"> Minimal 8 karakter</span><br>
<span :class="passwordChecks.upper ? 'green--text' : 'red--text'"> Ada huruf besar (A-Z)</span><br>
<span :class="passwordChecks.lower ? 'green--text' : 'red--text'"> Ada huruf kecil (a-z)</span><br>
<span :class="passwordChecks.number ? 'green--text' : 'red--text'"> Ada angka (0-9)</span><br>
<span :class="passwordChecks.symbol ? 'green--text' : 'red--text'"> Ada simbol</span>
</div>
</v-flex> </v-flex>
<v-flex xs12 pa-1> <v-flex xs12 pa-1>
@@ -79,6 +90,7 @@ module.exports = {
username: '', username: '',
displayName: '', displayName: '',
password: '', password: '',
passwordTouched: false,
selectedProject: null, selectedProject: null,
projectKeyword: '', projectKeyword: '',
pendingProjects: [] pendingProjects: []
@@ -90,6 +102,23 @@ module.exports = {
assignedProjects() { return this.isEditMode ? (this.selectedUser.projects || []) : this.pendingProjects }, assignedProjects() { return this.isEditMode ? (this.selectedUser.projects || []) : this.pendingProjects },
dialogsuccess() { return this.$store.state.dashboard_user.dialog_success }, dialogsuccess() { return this.$store.state.dashboard_user.dialog_success },
msgsuccess() { return this.$store.state.dashboard_user.msg_success }, msgsuccess() { return this.$store.state.dashboard_user.msg_success },
passwordChecks() {
let pwd = this.password || ''
return {
length: pwd.length >= 8,
upper: /[A-Z]/.test(pwd),
lower: /[a-z]/.test(pwd),
number: /[0-9]/.test(pwd),
symbol: /[^A-Za-z0-9]/.test(pwd)
}
},
passwordReady() {
return this.passwordChecks.length
&& this.passwordChecks.upper
&& this.passwordChecks.lower
&& this.passwordChecks.number
&& this.passwordChecks.symbol
},
projectItems() { projectItems() {
return (this.$store.state.dashboard_user.project_options || []).map(p => { return (this.$store.state.dashboard_user.project_options || []).map(p => {
return Object.assign({}, p, { label: p.project_number + ' - ' + p.project_name }) return Object.assign({}, p, { label: p.project_number + ' - ' + p.project_name })
@@ -104,6 +133,7 @@ module.exports = {
this.username = val.User_Username || '' this.username = val.User_Username || ''
this.displayName = val.User_DisplayName || '' this.displayName = val.User_DisplayName || ''
this.password = '' this.password = ''
this.passwordTouched = false
if (val && val.User_ID) this.pendingProjects = [] if (val && val.User_ID) this.pendingProjects = []
} }
}, },
@@ -140,6 +170,7 @@ module.exports = {
return false return false
} }
if (requirePassword) { if (requirePassword) {
this.passwordTouched = true
let pwd = this.password || '' let pwd = this.password || ''
if (pwd.length < 8) { if (pwd.length < 8) {
alert('Password minimal 8 karakter') alert('Password minimal 8 karakter')
@@ -170,6 +201,7 @@ module.exports = {
} }
this.pendingProjects = [] this.pendingProjects = []
} }
this.passwordTouched = false
this.$store.commit('dashboard_user/update_selected_user', {}) this.$store.commit('dashboard_user/update_selected_user', {})
this.refreshList() this.refreshList()
} else { } else {
@@ -258,6 +290,7 @@ module.exports = {
this.username = '' this.username = ''
this.displayName = '' this.displayName = ''
this.password = '' this.password = ''
this.passwordTouched = false
this.selectedProject = null this.selectedProject = null
this.projectKeyword = '' this.projectKeyword = ''
this.pendingProjects = [] this.pendingProjects = []