diff --git a/src/app/modules/main/profile_section/privacy/controller.nim b/src/app/modules/main/profile_section/privacy/controller.nim index 5ffdb729b0..c6db6c7769 100644 --- a/src/app/modules/main/profile_section/privacy/controller.nim +++ b/src/app/modules/main/profile_section/privacy/controller.nim @@ -57,3 +57,6 @@ method getMessagesFromContactsOnly*(self: Controller): bool = method setMessagesFromContactsOnly*(self: Controller, value: bool): bool = return self.settingsService.saveMessagesFromContactsOnly(value) + +method validatePassword*(self: Controller, password: string): bool = + return self.privacyService.validatePassword(password) diff --git a/src/app/modules/main/profile_section/privacy/controller_interface.nim b/src/app/modules/main/profile_section/privacy/controller_interface.nim index b8f6d48f45..99816a9321 100644 --- a/src/app/modules/main/profile_section/privacy/controller_interface.nim +++ b/src/app/modules/main/profile_section/privacy/controller_interface.nim @@ -31,3 +31,6 @@ method getMessagesFromContactsOnly*(self: AccessInterface): bool {.base.} = method setMessagesFromContactsOnly*(self: AccessInterface, value: bool): bool {.base.} = raise newException(ValueError, "No implementation available") + +method validatePassword*(self: AccessInterface, password: string): bool {.base.} = + raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/profile_section/privacy/io_interface.nim b/src/app/modules/main/profile_section/privacy/io_interface.nim index cb24ea6d40..ab358d5afc 100644 --- a/src/app/modules/main/profile_section/privacy/io_interface.nim +++ b/src/app/modules/main/profile_section/privacy/io_interface.nim @@ -52,3 +52,6 @@ method getMessagesFromContactsOnly*(self: AccessInterface): bool {.base.} = method setMessagesFromContactsOnly*(self: AccessInterface, value: bool) {.base.} = raise newException(ValueError, "No implementation available") + +method validatePassword*(self: AccessInterface, password: string): bool {.base.} = + raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/profile_section/privacy/module.nim b/src/app/modules/main/profile_section/privacy/module.nim index ff59dfc2f2..204ced2516 100644 --- a/src/app/modules/main/profile_section/privacy/module.nim +++ b/src/app/modules/main/profile_section/privacy/module.nim @@ -75,3 +75,6 @@ method getMessagesFromContactsOnly*(self: Module): bool = method setMessagesFromContactsOnly*(self: Module, value: bool) = if(not self.controller.setMessagesFromContactsOnly(value)): error "an error occurred while saving messages from contacts only flag" + +method validatePassword*(self: Module, password: string): bool = + self.controller.validatePassword(password) diff --git a/src/app/modules/main/profile_section/privacy/view.nim b/src/app/modules/main/profile_section/privacy/view.nim index 2df14cfd18..efe185a5ca 100644 --- a/src/app/modules/main/profile_section/privacy/view.nim +++ b/src/app/modules/main/profile_section/privacy/view.nim @@ -57,3 +57,6 @@ QtObject: read = getMessagesFromContactsOnly write = setMessagesFromContactsOnly notify = messagesFromContactsOnlyChanged + + proc validatePassword*(self: View, password: string): bool {.slot.} = + self.delegate.validatePassword(password) diff --git a/src/app_service/service/privacy/service.nim b/src/app_service/service/privacy/service.nim index a95eec5748..ed5b2496de 100644 --- a/src/app_service/service/privacy/service.nim +++ b/src/app_service/service/privacy/service.nim @@ -130,3 +130,21 @@ QtObject: return return mnemonics[index] + + proc validatePassword*(self: Service, password: string): bool = + try: + let defaultAccount = self.getDefaultAccount() + + if(defaultAccount.len == 0): + error "error: ", methodName="validatePassword", errDesription = "default eth account is empty" + return false + + let isPasswordOk = self.accountsService.verifyAccountPassword(defaultAccount, password) + if not isPasswordOk: + error "error: ", methodName="validatePassword", errDesription = "password cannnot be verified" + return false + + return true + except Exception as e: + error "error: ", methodName="validatePassword", errName = e.name, errDesription = e.msg + return false diff --git a/ui/app/AppLayouts/Onboarding/shared/CreatePasswordModal.qml b/ui/app/AppLayouts/Onboarding/shared/CreatePasswordModal.qml index dbc1591cca..1c9eb34f0e 100644 --- a/ui/app/AppLayouts/Onboarding/shared/CreatePasswordModal.qml +++ b/ui/app/AppLayouts/Onboarding/shared/CreatePasswordModal.qml @@ -12,6 +12,7 @@ import shared.controls 1.0 // TODO: replace with StatusModal ModalPopup { + property var privacyStore property bool loading: false property bool firstPasswordFieldValid: false property bool repeatPasswordFieldValid: false @@ -45,6 +46,8 @@ ModalPopup { onTextChanged: { [firstPasswordFieldValid, passwordValidationError] = Utils.validatePasswords("first", firstPasswordField, repeatPasswordField); + [repeatPasswordFieldValid, repeatPasswordValidationError] = + Utils.validatePasswords("repeat", firstPasswordField, repeatPasswordField); } } @@ -159,8 +162,16 @@ ModalPopup { onClicked: { if (storingPasswordModal) { - Global.applicationWindow.prepareForStoring(repeatPasswordField.text, true) - popup.close() + // validate the entered password + var validatePassword = privacyStore.validatePassword(repeatPasswordField.text) + if(!validatePassword) { + firstPasswordFieldValid = false + passwordValidationError = qsTr("Incorrect password") + } + else { + Global.applicationWindow.prepareForStoring(repeatPasswordField.text, true) + popup.close() + } } else { diff --git a/ui/app/AppLayouts/Onboarding/views/LoginView.qml b/ui/app/AppLayouts/Onboarding/views/LoginView.qml index 48ae859e21..1485ca8f1c 100644 --- a/ui/app/AppLayouts/Onboarding/views/LoginView.qml +++ b/ui/app/AppLayouts/Onboarding/views/LoginView.qml @@ -39,7 +39,6 @@ Item { if(localAccountSettings.storeToKeychainValue === Constants.storeToKeychainValueStore) { connection.enabled = true - txtPassword.visible = false } else { diff --git a/ui/app/AppLayouts/Profile/popups/StoreToKeychainSelectionModal.qml b/ui/app/AppLayouts/Profile/popups/StoreToKeychainSelectionModal.qml index 51e2ae70ca..cbd37f4e3f 100644 --- a/ui/app/AppLayouts/Profile/popups/StoreToKeychainSelectionModal.qml +++ b/ui/app/AppLayouts/Profile/popups/StoreToKeychainSelectionModal.qml @@ -12,6 +12,8 @@ import "../../Onboarding/shared" as OnboardingComponents ModalPopup { id: popup + property var privacyStore + title: qsTr("Store pass to Keychain") onClosed: { @@ -95,6 +97,7 @@ ModalPopup { Component { id: storePasswordModal OnboardingComponents.CreatePasswordModal { + privacyStore: popup.privacyStore storingPasswordModal: true height: 350 } diff --git a/ui/app/AppLayouts/Profile/stores/PrivacyStore.qml b/ui/app/AppLayouts/Profile/stores/PrivacyStore.qml index 84146997d1..5b29f24aa6 100644 --- a/ui/app/AppLayouts/Profile/stores/PrivacyStore.qml +++ b/ui/app/AppLayouts/Profile/stores/PrivacyStore.qml @@ -28,4 +28,8 @@ QtObject { function getMnemonicWordAtIndex(index) { return root.privacyModule.getMnemonicWordAtIndex(index) } + + function validatePassword(password) { + return root.privacyModule.validatePassword(password) + } } diff --git a/ui/app/AppLayouts/Profile/views/PrivacyView.qml b/ui/app/AppLayouts/Profile/views/PrivacyView.qml index 79fed9f86d..b3889da1d1 100644 --- a/ui/app/AppLayouts/Profile/views/PrivacyView.qml +++ b/ui/app/AppLayouts/Profile/views/PrivacyView.qml @@ -111,7 +111,9 @@ Item { Component { id: storeToKeychainSelectionModal - StoreToKeychainSelectionModal {} + StoreToKeychainSelectionModal { + privacyStore: root.privacyStore + } } }