fix(PasswordView): Space is not allowed in password

Update new password input validators to allow any character input and show error message if the character is invalid.
This commit is contained in:
Alex Jbanca 2023-06-26 13:56:08 +03:00 committed by Alex Jbanca
parent 7dbf994e1f
commit 48c7d875de
3 changed files with 94 additions and 10 deletions

View File

@ -69,6 +69,10 @@ ListModel {
title: "DeviceSyncingView" title: "DeviceSyncingView"
section: "Views" section: "Views"
} }
ListElement {
title: "PasswordView"
section: "Views"
}
ListElement { ListElement {
title: "CommunitiesView" title: "CommunitiesView"
section: "Views" section: "Views"

View File

@ -0,0 +1,69 @@
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import QtQuick.Extras 1.4
import shared.views 1.0
import Storybook 1.0
SplitView {
orientation: Qt.Vertical
Logs { id: logs }
Item {
id: wrapper
SplitView.fillWidth: true
SplitView.fillHeight: true
PasswordView {
id: passwordView
width: 460
height: 416
anchors.centerIn: parent
onReturnPressed: logs.logEvent("Return pressed", ["Current Password", "New Password", "Confirmation Password"], [passwordView.currentPswText, passwordView.newPswText, passwordView.confirmationPswText])
createNewPsw: createNewPassword.checked
titleVisible: titleVisibleSwitch.checked
highSizeIntro: highSizeIntroSwitch.checked
passwordStrengthScoreFunction: (newPass) => Math.min(newPass.length, 4)
}
}
LogsAndControlsPanel {
id: logsAndControlsPanel
SplitView.minimumHeight: 100
SplitView.preferredHeight: 150
logsView.logText: logs.logText
RowLayout {
StatusIndicator {
color: "green"
active: passwordView.ready
}
Text {
leftPadding: 10
text: "Ready"
}
Switch {
id: createNewPassword
text: "Create new password"
}
Switch {
id: highSizeIntroSwitch
text: "High size Intro"
}
Switch {
id: titleVisibleSwitch
text: "Title visible"
}
}
}
}

View File

@ -54,7 +54,6 @@ ColumnLayout {
function checkPasswordMatches(onlyIfConfirmPasswordHasFocus = true) { function checkPasswordMatches(onlyIfConfirmPasswordHasFocus = true) {
if (confirmPswInput.text.length === 0) { if (confirmPswInput.text.length === 0) {
errorTxt.text = ""
return return
} }
@ -63,7 +62,6 @@ ColumnLayout {
} }
if(newPswInput.text.length >= Constants.minPasswordLength) { if(newPswInput.text.length >= Constants.minPasswordLength) {
errorTxt.text = ""
if(confirmPswInput.text !== newPswInput.text) { if(confirmPswInput.text !== newPswInput.text) {
errorTxt.text = qsTr("Passwords don't match") errorTxt.text = qsTr("Passwords don't match")
} }
@ -78,7 +76,8 @@ ColumnLayout {
property bool containsNumbers: false property bool containsNumbers: false
property bool containsSymbols: false property bool containsSymbols: false
readonly property var validator: RegExpValidator { regExp: /^[!-~]{0,64}$/ } // That incudes NOT extended ASCII printable characters less space and a maximum of 64 characters allowed readonly property var validatorRegexp: /^[!-~]{0,64}$/
readonly property string validatorErrMessage: qsTr("Only letters, numbers, underscores and hyphens allowed")
// Password strength categorization / validation // Password strength categorization / validation
function lowerCaseValidator(text) { return (/[a-z]/.test(text)) } function lowerCaseValidator(text) { return (/[a-z]/.test(text)) }
@ -87,6 +86,15 @@ ColumnLayout {
// That incudes NOT extended ASCII printable symbols less space: // That incudes NOT extended ASCII printable symbols less space:
function symbolsValidator(text) { return (/[!-\/:-@[-`{-~]/.test(text)) } function symbolsValidator(text) { return (/[!-\/:-@[-`{-~]/.test(text)) }
function validateCharacterSet(text) {
if(!(d.validatorRegexp).test(text)) {
errorTxt.text = d.validatorErrMessage
return false
}
return true
}
// Used to convert strength from a given score to a specific category // Used to convert strength from a given score to a specific category
function convertStrength(score) { function convertStrength(score) {
var strength = StatusPasswordStrengthIndicator.Strength.None var strength = StatusPasswordStrengthIndicator.Strength.None
@ -104,8 +112,6 @@ ColumnLayout {
// Password validation / error message selection: // Password validation / error message selection:
function passwordValidation() { function passwordValidation() {
errorTxt.text = ""
// 3 rules to validate: // 3 rules to validate:
// * Password is in pwnd passwords database // * Password is in pwnd passwords database
if(isInPwndDatabase()) if(isInPwndDatabase())
@ -168,7 +174,6 @@ ColumnLayout {
Layout.fillWidth: true Layout.fillWidth: true
placeholderText: qsTr("Current password") placeholderText: qsTr("Current password")
echoMode: showPassword ? TextInput.Normal : TextInput.Password echoMode: showPassword ? TextInput.Normal : TextInput.Password
validator: d.validator
rightPadding: showHideCurrentIcon.width + showHideCurrentIcon.anchors.rightMargin + Style.current.padding / 2 rightPadding: showHideCurrentIcon.width + showHideCurrentIcon.anchors.rightMargin + Style.current.padding / 2
onAccepted: root.returnPressed() onAccepted: root.returnPressed()
@ -201,18 +206,21 @@ ColumnLayout {
Layout.fillWidth: true Layout.fillWidth: true
placeholderText: qsTr("New password") placeholderText: qsTr("New password")
echoMode: showPassword ? TextInput.Normal : TextInput.Password echoMode: showPassword ? TextInput.Normal : TextInput.Password
validator: d.validator
rightPadding: showHideNewIcon.width + showHideNewIcon.anchors.rightMargin + Style.current.padding / 2 rightPadding: showHideNewIcon.width + showHideNewIcon.anchors.rightMargin + Style.current.padding / 2
onTextChanged: { onTextChanged: {
// Update password checkers // Update password checkers
errorTxt.text = ""
// Update strength indicator:
strengthInditactor.strength = d.convertStrength(root.passwordStrengthScoreFunction(newPswInput.text))
if(!d.validateCharacterSet(text)) return
d.containsLower = d.lowerCaseValidator(text) d.containsLower = d.lowerCaseValidator(text)
d.containsUpper = d.upperCaseValidator(text) d.containsUpper = d.upperCaseValidator(text)
d.containsNumbers = d.numbersValidator(text) d.containsNumbers = d.numbersValidator(text)
d.containsSymbols = d.symbolsValidator(text) d.containsSymbols = d.symbolsValidator(text)
// Update strength indicator:
strengthInditactor.strength = d.convertStrength(root.passwordStrengthScoreFunction(newPswInput.text))
if (text.length === confirmPswInput.text.length) { if (text.length === confirmPswInput.text.length) {
root.checkPasswordMatches(false) root.checkPasswordMatches(false)
} }
@ -302,10 +310,13 @@ ColumnLayout {
Layout.fillWidth: true Layout.fillWidth: true
placeholderText: qsTr("Confirm password") placeholderText: qsTr("Confirm password")
echoMode: showPassword ? TextInput.Normal : TextInput.Password echoMode: showPassword ? TextInput.Normal : TextInput.Password
validator: d.validator
rightPadding: showHideConfirmIcon.width + showHideConfirmIcon.anchors.rightMargin + Style.current.padding / 2 rightPadding: showHideConfirmIcon.width + showHideConfirmIcon.anchors.rightMargin + Style.current.padding / 2
onTextChanged: { onTextChanged: {
errorTxt.text = ""
if(!d.validateCharacterSet(newPswInput.text)) return
d.passwordValidation(); d.passwordValidation();
if(text.length === newPswInput.text.length) { if(text.length === newPswInput.text.length) {
root.checkPasswordMatches() root.checkPasswordMatches()