Skip to content

Commit d57b6bf

Browse files
authored
Merge pull request #8350 from nextcloud-libraries/fix/noid/password-validate
2 parents a60b485 + 9a9ae60 commit d57b6bf

2 files changed

Lines changed: 32 additions & 10 deletions

File tree

src/components/NcPasswordField/NcPasswordField.vue

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ General purpose password field component.
1919
<NcPasswordField v-model="text2"
2020
id="textField"
2121
:label-outside="true"
22-
placeholder="Min. 12 characters" />
22+
placeholder="Min. 12 characters"
23+
:success="true"
24+
helper-text="Password is secure" />
2325
</div>
2426
<div class="external-label">
2527
<label for="textField2">New password</label>
@@ -32,10 +34,9 @@ General purpose password field component.
3234
</div>
3335

3436
<NcPasswordField v-model="text4"
35-
label="Good new password"
36-
:success="true"
37-
placeholder="Min. 12 characters"
38-
helper-text="Password is secure">
37+
label="Validate new password"
38+
check-password-strength
39+
placeholder="Min. 12 characters">
3940
<template #icon>
4041
<IconLockOutline :size="20" />
4142
</template>
@@ -57,7 +58,7 @@ export default {
5758
data() {
5859
return {
5960
text1: '',
60-
text2: '',
61+
text2: 'FWZxt29XEoTQfnBEa',
6162
text3: 'hunter',
6263
text4: '',
6364
text5: '',
@@ -152,8 +153,6 @@ const emit = defineEmits<{
152153
invalid: []
153154
}>()
154155
155-
watch(modelValue, debounce(checkPassword, 500))
156-
157156
// public API
158157
defineExpose({
159158
focus,
@@ -232,12 +231,19 @@ const minLengthWithPolicy = computed(() => {
232231
?? undefined
233232
})
234233
234+
watch(modelValue, () => {
235+
// Reset internal validation state on value change, before debounced checkPassword() is called
236+
isValid.value = undefined
237+
internalHelpMessage.value = ''
238+
})
239+
watch(modelValue, debounce(checkPassword, 500))
240+
235241
/**
236242
* Validate the entered password.
237243
* If available this method will use the password-policy app API to validate the password.
238244
*/
239245
async function checkPassword() {
240-
if (!props.checkPasswordStrength) {
246+
if (!props.checkPasswordStrength || !modelValue.value) {
241247
return
242248
}
243249

styleguide/global.requires.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const USER_GROUPS = [
2828
* @param {object} error Axios error
2929
*/
3030
function mockRequests(error) {
31-
const { request } = error
31+
const { request, config } = error
3232
let data = null
3333

3434
// Mock resolved link references for NcRichText
@@ -58,6 +58,22 @@ function mockRequests(error) {
5858
data = { groups: USER_GROUPS.filter((e) => !requestGroups[1] || e.displayname.startsWith(requestGroups[1]) || e.id.startsWith(requestGroups[1])) }
5959
}
6060

61+
const requestPasswordPolicy = request.responseURL.match(/apps\/password_policy\/api\/v1\/validate/)
62+
if (requestPasswordPolicy) {
63+
const payload = typeof config.data === 'string' ? JSON.parse(config.data) : config.data
64+
65+
if (payload.password.length < 12) {
66+
data = {
67+
passed: false,
68+
reason: 'Password needs to be at least 12 characters long',
69+
}
70+
} else {
71+
data = {
72+
passed: true,
73+
}
74+
}
75+
}
76+
6177
if (data) {
6278
return Promise.resolve({ data: { ocs: { data } } })
6379
}

0 commit comments

Comments
 (0)