initial commit
This commit is contained in:
56
app/stores/passwordToolBox.ts
Normal file
56
app/stores/passwordToolBox.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const usePasswordToolBoxStore = defineStore('passwordToolBox', {
|
||||
state: () => ({
|
||||
password: '',
|
||||
confirmPassword: '',
|
||||
|
||||
// --- REGEX ---
|
||||
regNumberOfCaracteres: /^.{8,22}$/,
|
||||
regSpecialCaractere: /[^A-Za-z0-9]/,
|
||||
regCapitalizeCaractere: /[A-Z]/,
|
||||
regMinimizeCaractere: /[a-z]/,
|
||||
regNumber: /\d/,
|
||||
regPassword: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{8,22}$/,
|
||||
}),
|
||||
actions: {
|
||||
updatePassword(newPassword: string) {
|
||||
this.password = newPassword
|
||||
},
|
||||
updateConfirmPassword(newConfirm: string) {
|
||||
this.confirmPassword = newConfirm
|
||||
},
|
||||
|
||||
// --- CHECK FUNCTIONS ---
|
||||
checkRegex(regex: RegExp) {
|
||||
return regex.test(this.password)
|
||||
},
|
||||
|
||||
isNumberOfCaracteresValid() {
|
||||
return this.checkRegex(this.regNumberOfCaracteres)
|
||||
},
|
||||
isSpecialCaractereValid() {
|
||||
return this.checkRegex(this.regSpecialCaractere)
|
||||
},
|
||||
isCapitalizeCaractereValid() {
|
||||
return this.checkRegex(this.regCapitalizeCaractere)
|
||||
},
|
||||
isMinimizeCaractereValid() {
|
||||
return this.checkRegex(this.regMinimizeCaractere)
|
||||
},
|
||||
isNumberValid() {
|
||||
return this.checkRegex(this.regNumber)
|
||||
},
|
||||
isPasswordValid() {
|
||||
return this.checkRegex(this.regPassword)
|
||||
},
|
||||
isPasswordConfirmationValid() {
|
||||
return this.password === this.confirmPassword && this.isPasswordValid()
|
||||
},
|
||||
|
||||
// --- UI HELPER ---
|
||||
uiClass(valid: boolean) {
|
||||
return valid ? 'has-success' : 'has-error'
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user