Skip to content

Commit

Permalink
Merge pull request #25 from nevissecurity/feature/NEVISACCESSAPP-5973
Browse files Browse the repository at this point in the history
NEVISACCESSAPP-5973: Modified Password Policy
  • Loading branch information
tamas-toth authored Aug 6, 2024
2 parents 61bb050 + 17aad98 commit 4af294a
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 9 deletions.
3 changes: 0 additions & 3 deletions .jazzy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ custom_categories:
- SharedSequenceConvertibleType
- Result
- String?
- UIApplication
- UINavigationController
- UIStackView
- UIView
Expand All @@ -108,9 +107,7 @@ custom_categories:
- AccountSelectorImpl
- AuthenticatorSelectorImpl
- AuthenticationAuthenticatorSelectorName
- AuthenticationAuthenticatorSelectorImpl
- RegistrationAuthenticatorSelectorName
- RegistrationAuthenticatorSelectorImpl
- PinUserVerifierImpl
- PasswordUserVerifierImpl
- BiometricUserVerifierImpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ let AuthenticationAuthenticatorSelectorName = "auth_selector_auth"
/// With the help of the ``ResponseEmitter`` it will emit a ``SelectAuthenticatorResponse``.
class AuthenticatorSelectorImpl {

/// Supported operations for authenticator selection.
enum Operation {
/// Registration operation.
case registration
/// Authentication operation.
case authentication
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ extension InBandAuthenticationUseCaseImpl: InBandAuthenticationUseCase {
// MARK: - Private Interface

private extension InBandAuthenticationUseCaseImpl {
/// Prints authorization information to the console.
///
/// - Parameter authorizationProvider: The ``AuthorizationProvider`` holding the authorization information.
func printAuthorizationInfo(_ authorizationProvider: AuthorizationProvider?) {
if let cookieAuthorizationProvider = authorizationProvider as? CookieAuthorizationProvider {
logger.log("Received cookies: \(cookieAuthorizationProvider.cookies)")
Expand All @@ -121,6 +124,9 @@ private extension InBandAuthenticationUseCaseImpl {
}
}

/// Prints session information to the console.
///
/// - Parameter sessionProvider: The ``SessionProvider`` holding the session information.
func printSessionInfo(_ sessionProvider: SessionProvider?) {
if let cookieSessionProvider = sessionProvider as? CookieSessionProvider {
logger.log("Received cookies: \(cookieSessionProvider.cookies)")
Expand Down
31 changes: 26 additions & 5 deletions NevisExampleApp/Domain/Validators/PasswordPolicyImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,40 @@

import NevisMobileAuthentication

/// Password policy related errors.
enum PasswordPolicyError: Error {
/// Invalid password.
case invalidPassword
}

extension PasswordPolicyError: LocalizedError {
/// A message describing what error occurred.
public var errorDescription: String? {
switch self {
case .invalidPassword:
L10n.Credential.Password.Policy.errorCause
}
}
}

/// Implementation of the ``PasswordPolicy``.
/// This policy validates the password entered by the user during registration or password changing,
/// and allows only passwords longer than 6 characters.
/// and allows only passwords that are not equal to `password`.
final class PasswordPolicyImpl {}

// MARK: PasswordPolicy

extension PasswordPolicyImpl: PasswordPolicy {
func validatePasswordForEnrollment(_ password: String, onSuccess: @escaping () -> (), onError: @escaping (PasswordEnrollmentValidationError) -> ()) {
guard isValid(password) else {
return onError(.InvalidPassword(message: errorMessage))
return onError(.InvalidPassword(message: errorMessage, cause: PasswordPolicyError.invalidPassword))
}
onSuccess()
}

func validatePasswordForPasswordChange(_ password: String, onSuccess: @escaping () -> (), onError: @escaping (PasswordChangeValidationError) -> ()) {
guard isValid(password) else {
return onError(.InvalidPassword(message: errorMessage))
return onError(.InvalidPassword(message: errorMessage, cause: PasswordPolicyError.invalidPassword))
}
onSuccess()
}
Expand All @@ -32,11 +48,16 @@ extension PasswordPolicyImpl: PasswordPolicy {
// MARK: - Private extension

private extension PasswordPolicyImpl {
/// The validation error message.
var errorMessage: String {
"The password must be more than 6 characters."
L10n.Credential.Password.Policy.errorMessage
}

/// Returns a Boolean value indicating whether a password is valid.
///
/// - Parameter password: The password to validate.
/// - Returns: A Boolean value indicating whether a password is valid.
func isValid(_ password: String) -> Bool {
password.trimmingCharacters(in: .whitespacesAndNewlines).count >= 6
password.trimmingCharacters(in: .whitespacesAndNewlines) != "password"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ private extension SelectAccountViewModel {
authorizationProvider: authorizationProvider)
}
.flatMap(responseObserver.observe(response:))

case .pinChange:
return changePinUseCase.execute(username: account.username)
.flatMap(responseObserver.observe(response:))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,22 @@ extension AuthenticatorAaid: Codable {
}

extension AuthenticatorAaid {
/// Returns a Boolean value indicating whether a ``String`` and an ``AuthenticatorAaid`` are equal.
///
/// - Parameters:
/// - lhs: A ``String`` value to compare.
/// - rhs: An ``AuthenticatorAaid`` to compare.
/// - Returns: A Boolean value indicating whether the two values are equal.
static func == (lhs: String, rhs: AuthenticatorAaid) -> Bool {
rhs.rawValue == lhs
}

/// Returns a Boolean value indicating whether a ``String`` and an ``AuthenticatorAaid`` are equal.
///
/// - Parameters:
/// - lhs: An ``AuthenticatorAaid`` to compare.
/// - rhs: A ``String`` value to compare.
/// - Returns: A Boolean value indicating whether the two values are equal.
static func == (lhs: AuthenticatorAaid, rhs: String) -> Bool {
rhs == lhs.rawValue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,14 @@ enum L10n {
}
}

/// Password policy related localized strings.
enum Policy {
/// Error message: "The password must not be password."
static let errorMessage = L10n.tr("password_policy_error_message")
/// Error cause: "The password is password."
static let errorCause = L10n.tr("password_policy_error_cause")
}

/// Password field placeholder: "Enter Password"
static let passwordPlaceholder = L10n.tr("password_password_placeholder")
/// Password confirm field placeholder: "Enter old Password"
Expand Down Expand Up @@ -397,6 +405,7 @@ enum L10n {
static let title = L10n.tr("operation_device_information_change_title")
}

/// Local data related localized strings.
enum LocalData {
/// Operation title: "Local data operation"
static let title = L10n.tr("operation_local_data_title")
Expand Down
2 changes: 2 additions & 0 deletions NevisExampleApp/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
"password_protection_status_last_retry_without_cool_down" = "You have %@ try left.\nAfter that your Password will be blocked.";
"password_protection_status_retries_with_cool_down" = "You have %@ tries left.\nPlease retry in %@ seconds.";
"password_protection_status_retries_without_cool_down" = "You have %@ tries left.";
"password_policy_error_message" = "The password must not be password.";
"password_policy_error_cause" = "The password is password.";

// Transaction Confirmation screen
"transaction_confirmation_title" = "Transaction Confirmation";
Expand Down

0 comments on commit 4af294a

Please sign in to comment.