Created
November 7, 2018 11:42
-
-
Save andr3a88/ef8393f0602019b1983e154168888dfe to your computer and use it in GitHub Desktop.
Utils for password validation with different criterias
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension WTFViewModel { | |
let passwordMinChars: Int = 6 | |
let passwordMinCriterias: Int = 3 | |
/// Checks if the text meets the validity criteria | |
/// | |
/// - Parameter text: The text | |
/// - Returns: The result | |
private func isPasswordCriteriaSatisfied(text: String) -> Bool { | |
let capitalCriteria = text.evaluate(regex: ".*[A-Z]+.*", predicateFormat: "SELF MATCHES %@") | |
let lowerCriteria = text.evaluate(regex: ".*[a-z]+.*", predicateFormat: "SELF MATCHES %@") | |
let numberCriteria = text.evaluate(regex: ".*[0-9]+.*", predicateFormat: "SELF MATCHES %@") | |
let specialCriteria = text.evaluate(regex: ".*[!&^%$#@()/.,+-:_=?\\[\\]]+.*", predicateFormat: "SELF MATCHES %@") | |
return [capitalCriteria, lowerCriteria, numberCriteria, specialCriteria].filter({ $0 }).count >= passwordMinCriterias | |
&& text.count >= passwordMinChars | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment