Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Validate password strength.
- *
- * {{{
- * case class Model(password: String)
- *
- * val form: Form[Model] = {
- * import play.api.data.Forms._
- *
- * Form(
- * mapping(
- * "password" -> password
- * )(Model.apply)(Model.unapply)
- * )
- * }
- * }}}
- */
- val password: Mapping[String] = text(minLength = 8, maxLength = 32).verifying(
- "Password must contain at least 3 of the following: capital letter, lowercase letter, number, or symbol",
- value => {
- val codePoints: Seq[Int] = value.codePoints().toArray
- val categorizers: List[Int => Boolean] = List(
- (codePoint: Int) => Character.isUpperCase(codePoint),
- (codePoint: Int) => Character.isLowerCase(codePoint),
- (codePoint: Int) => Character.isDigit(codePoint),
- (codePoint: Int) => !Character.isLetterOrDigit(codePoint)
- )
- val count = categorizers.foldLeft(0) { (sum, categorizer) =>
- sum + (if (codePoints.exists(categorizer)) 1 else 0)
- }
- count >= 3
- }
- )
Add Comment
Please, Sign In to add comment