diff --git a/Sources/BraveWallet/Crypto/Stores/KeyringStore.swift b/Sources/BraveWallet/Crypto/Stores/KeyringStore.swift index 7ab61ade04f..9ca0f4aa91b 100644 --- a/Sources/BraveWallet/Crypto/Stores/KeyringStore.swift +++ b/Sources/BraveWallet/Crypto/Stores/KeyringStore.swift @@ -210,7 +210,15 @@ public class KeyringStore: ObservableObject { } func isStrongPassword(_ password: String, completion: @escaping (Bool) -> Void) { - keyringService.isStrongPassword(password, completion: completion) + completion(password.count >= 8) + } + + @MainActor func isStrongPassword(_ password: String) async -> Bool { + await withCheckedContinuation { continuation in + isStrongPassword(password) { isStrong in + continuation.resume(returning: isStrong) + } + } } func createWallet(password: String, completion: ((String) -> Void)? = nil) { diff --git a/Sources/BraveWallet/Preview Content/MockKeyringService.swift b/Sources/BraveWallet/Preview Content/MockKeyringService.swift index e7fc55bf7b7..e0279ca6805 100644 --- a/Sources/BraveWallet/Preview Content/MockKeyringService.swift +++ b/Sources/BraveWallet/Preview Content/MockKeyringService.swift @@ -263,35 +263,7 @@ class MockKeyringService: BraveWalletKeyringService { } func isStrongPassword(_ password: String, completion: @escaping (Bool) -> Void) { - do { - // Should match shared logic for testing, however this may not always be the case - let range = NSRange(location: 0, length: password.count) - if password.count < 7 { - completion(false) - return - } - // Has at least one letter - if (try NSRegularExpression(pattern: "[a-zA-Z]", options: [])) - .numberOfMatches(in: password, options: [], range: range) < 1 { - completion(false) - return - } - // Has at least one number - if (try NSRegularExpression(pattern: "[0-9]", options: [])) - .numberOfMatches(in: password, options: [], range: range) < 1 { - completion(false) - return - } - // Has at least one non-alphanumeric - if (try NSRegularExpression(pattern: "[^0-9a-zA-Z]", options: [])) - .numberOfMatches(in: password, options: [], range: range) < 1 { - completion(false) - return - } - completion(true) - } catch { - completion(false) - } + completion(password.count >= 8) } func checksumEthAddress(_ address: String, completion: @escaping (String) -> Void) { diff --git a/Sources/BraveWallet/WalletStrings.swift b/Sources/BraveWallet/WalletStrings.swift index 007a730d874..fb3d4d85b68 100644 --- a/Sources/BraveWallet/WalletStrings.swift +++ b/Sources/BraveWallet/WalletStrings.swift @@ -635,7 +635,7 @@ extension Strings { "wallet.passwordDoesNotMeetRequirementsError", tableName: "BraveWallet", bundle: .module, - value: "Passwords must be at least 7 characters, and contain at least one letter, one number, and one special character.", + value: "Passwords must be at least 8 characters.", comment: "The error message displayed when a user enters a password that does not meet the requirements" ) public static let passwordsDontMatchError = NSLocalizedString( diff --git a/Tests/BraveWalletTests/KeyringStoreTests.swift b/Tests/BraveWalletTests/KeyringStoreTests.swift index 193149c120d..ff34dad6234 100644 --- a/Tests/BraveWalletTests/KeyringStoreTests.swift +++ b/Tests/BraveWalletTests/KeyringStoreTests.swift @@ -107,4 +107,35 @@ class KeyringStoreTests: XCTestCase { XCTAssertNil(error) } } + + @MainActor func testIsStrongPassword() async { + let (keyringService, rpcService, walletService) = setupServices() + let store = KeyringStore( + keyringService: keyringService, + walletService: walletService, + rpcService: rpcService + ) + + let invalidPassword1 = "" + var isStrongPassword = await store.isStrongPassword(invalidPassword1) + XCTAssertFalse(isStrongPassword) + + let invalidPassword2 = "1234" + isStrongPassword = await store.isStrongPassword(invalidPassword2) + XCTAssertFalse(isStrongPassword) + + let validPassword = "12345678" + isStrongPassword = await store.isStrongPassword(validPassword) + XCTAssertTrue(isStrongPassword) + + let uuid = UUID().uuidString + // first 30 characters of uuid + let validPassword2 = String(uuid[uuid.startIndex..