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 TextField { id: passwordTextField Layout.fillWidth: true echoMode: TextInput.Password placeholderText: qsTr("Pick a password") } 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 } TextField { id: confirmationPasswordTextField Layout.fillWidth: true echoMode: TextInput.Password placeholderText: qsTr("Confirm password") } 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 } }