Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PlayFramework中JSON中的密码验证_Json_Validation_Playframework - Fatal编程技术网

PlayFramework中JSON中的密码验证

PlayFramework中JSON中的密码验证,json,validation,playframework,Json,Validation,Playframework,我正在尝试创建一个自定义验证,该验证将检查密码是否包含至少1个特殊字符,并且至少包含8个字符。我会像这样使用它 (JsPath \ "user" \ "password").read[String] (checkPassword) val checkPassword: Reads[String] = { } 我希望checkPassword看起来像 (JsPath \ "user" \ "password").read[String] (checkPassword) val chec

我正在尝试创建一个自定义验证,该验证将检查密码是否包含至少1个特殊字符,并且至少包含8个字符。我会像这样使用它

(JsPath \ "user" \ "password").read[String] (checkPassword) 
val checkPassword: Reads[String] = {

}
我希望checkPassword看起来像

(JsPath \ "user" \ "password").read[String] (checkPassword) 
val checkPassword: Reads[String] = {

}
在这一点之后我迷路了:

  • 如何从
    (JsPath\“user”\“password”)提取密码。读取发送到
    checkPassword
    的[String]
    ?如何在
    checkPassword
    中访问它。我用“这个”吗?“这个”是什么类型的
  • 如何从
    checkPassword
    返回读取的
    Reads

  • 您可以使用
    验证
    验证:

    import play.api.libs.json.Reads._
    
    def passwordChecker(password: String): Boolean = 
      (password.length() > 7) && password.contains("$")
    
    val userReaders = (
        (JsPath \ "name").read[String] and
        (JsPath \ "password").read[String](verifying(passwordChecker))
      )(User)
    

    您可以查看默认验证器,了解如何实现您自己的验证器:谢谢。我来试试代码。不知道,read需要一个Reads类型的参数。
    验证
    将如何工作?我相信我以前在表单中看到过
    验证
    。其签名是def验证(错误:⇒ 字符串,约束:(T)⇒ 布尔):映射[T]
    def验证(约束:(T)⇒ 布尔):映射[T]
    在这里:或2.x的这里: