PasswordStrengthRules
@objc
public class PasswordStrengthRules : NSObject, InitializationStateProvider
Specify a set of password requirements to check via checkPasswordStrength(_:)
Default values
In the absence of a custom rule set, password strength checking operates on the basis of a minimum length of 6 characters, containing at least one upper case character and one digit.
Creating a custom rule
A custom rule can be created in two ways:
- directly as a
PasswordStrengthRules
object, in which case the rule is created with all checks disabled - via
getPasswordStrengthRules()
, in which case the rule is created with the current settings, which can then be modified
Setting the rule
For example, to apply only the rule elements you wish to specify:-
// create a rules object
let rules = PasswordStrengthRules()
rules.setMinimumLength(6)
// set the rules
ManageRules.setPasswordStrengthRules(rules)
-
Set the minimum length required.
Declaration
Swift
@discardableResult public func setMinimumLength(_ length: Int) -> PasswordStrengthRules
-
Set the upper case requirement.
Declaration
Swift
@discardableResult public func setRequireUpperCase(_ isRequired: Bool) -> PasswordStrengthRules
-
Set the numerical digit requirement.
Declaration
Swift
@discardableResult public func setRequireNumber(_ isRequired: Bool) -> PasswordStrengthRules
-
Set the requirement for a special character. This will be any character recognized by ctype ispunct().
Declaration
Swift
@discardableResult public func setRequireSpecialChar(_ isRequired: Bool) -> PasswordStrengthRules
-
Set the maximum number of occurrences for any character. The occurrences do not need to be consecutive.
Declaration
Swift
@discardableResult public func setMaximumRepeats(_ num: Int) -> PasswordStrengthRules
-
Set whether a numerical sequence is permitted. A sequence could be ascending or descending.
Declaration
Swift
@discardableResult public func setPreventNumericSequence(_ isRequired: Bool) -> PasswordStrengthRules