import QtQuick 2.9 import QtQuick.Controls 2.2 import QtQuick.Layouts 1.2 ColumnLayout { id: root readonly property alias password: passwordTextField.text readonly property bool isValidPassword: isLongEnough && hasLower && hasUpper && hasNumbers && hasSpecialChar && confirmationMatches readonly property bool isLongEnough: passwordTextField.text.length >= 12 readonly property bool hasLower: passwordTextField.text.search(/[a-z]/) >= 0 readonly property bool hasUpper: passwordTextField.text.search(/[A-Z/]/) >= 0 readonly property bool hasNumbers: passwordTextField.text.search(/[0-9]/) >= 0 readonly property bool hasSpecialChar: passwordTextField.text.search(/[\*!"$%&/()=?`'+#'¡^°²³¼\[\]|{}\\@]/) >= 0 readonly property bool confirmationMatches: passwordTextField.text === confirmationPasswordTextField.text property bool hiddenPassword: true RowLayout { TextField { id: passwordTextField Layout.fillWidth: true echoMode: root.hiddenPassword ? TextInput.Password : TextInput.Normal placeholderText: qsTr("Pick a password") } ColorIcon { Layout.preferredHeight: app.iconSize Layout.preferredWidth: app.iconSize name: "../images/eye.svg" color: root.hiddenPassword ? keyColor : app.accentColor MouseArea { anchors.fill: parent onClicked: { root.hiddenPassword = !root.hiddenPassword } } } } Label { Layout.fillWidth: true wrapMode: Text.WordWrap // TRANSLATORS: %1 will be replaced with the normal text color, %2 the color for the length check text: qsTr("The password needs to be least 12 characters long, contain lowercase, uppercase letters as well as numbers and special characters.") .arg(app.accentColor) .arg(!root.isLongEnough ? "red" : app.accentColor) .arg(!root.hasLower ? "red" : app.accentColor) .arg(!root.hasUpper ? "red" : app.accentColor) .arg(!root.hasNumbers ? "red" : app.accentColor) .arg(!root.hasSpecialChar ? "red" : app.accentColor) font.pixelSize: app.smallFont } RowLayout { TextField { id: confirmationPasswordTextField Layout.fillWidth: true echoMode: root.hiddenPassword ? TextInput.Password : TextInput.Normal placeholderText: qsTr("Confirm password") } ColorIcon { Layout.preferredHeight: app.iconSize Layout.preferredWidth: app.iconSize name: "../images/eye.svg" color: root.hiddenPassword ? keyColor : app.accentColor MouseArea { anchors.fill: parent onClicked: { root.hiddenPassword = !root.hiddenPassword } } } } Label { Layout.fillWidth: true wrapMode: Text.WordWrap text: root.confirmationMatches ? qsTr("The passwords match.").arg(app.accentColor) : qsTr("The passwords do not match.").arg(app.accentColor).arg("red") font.pixelSize: app.smallFont } }