2017-07-03 47 views
2

我已將密碼強度添加到我的用戶密碼。密碼強度無法重置密碼Symfony

/** 
* @Assert\Regex(
* pattern="/(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).{7,}/", 
* message="Uw wachtwoord moet zeven tekens of langer zijn, minimaal één getal bevatten, een hoofletter en een kleine letter. " 
*) 
*/ 
protected $plainPassword; 

這工作正常,但如果用戶想要重置其密碼,這些密碼強度規則不適用。

如何將密碼強度添加到重置密碼錶單中?

+0

您正在使用fosuserbundle? – ahmedbhs

+0

是的,我似乎它仍然使用默認的FOSUserBundle密碼強度值 –

+0

你談論改變密碼或通過郵件重新排序,你可以給我的網址! – ahmedbhs

回答

2
// vendor/friendsofsymfony/user-bundle/Ressources/config/validation.xml 
    <property name="plainPassword"> 
     <constraint name="NotBlank"> 
      <option name="message">fos_user.password.blank</option> 
      <option name="groups"> 
       <value>Registration</value> 
       <value>ResetPassword</value> 
       <value>ChangePassword</value> 
      </option> 
     </constraint> 
     <constraint name="Length"> 
      <option name="min">2</option> 
      <option name="max">4096</option> 
      <option name="minMessage">fos_user.password.short</option> 
      <option name="groups"> 
       <value>Registration</value> 
       <value>Profile</value> 
       <value>ResetPassword</value> 
       <value>ChangePassword</value> 
      </option> 
     </constraint> 
    </property> 

上面只是從fosuserbundle複製粘貼。正如你所看到的,fosuserbundle添加了組ResetPassword。試試這也使

/** 
* @Assert\Regex(
* pattern="/(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).{7,}/", 
* message="Uw wachtwoord moet zeven tekens of langer zijn, minimaal één getal bevatten, een hoofletter en een kleine letter. ", 
* groups = { "ResetPassword"} 
*) 
*/ 
protected $plainPassword; 

更新

所有你需要做的就是行

* groups = { "ResetPassword"} 

添加到$ plainPassword註解。

+0

我已添加您在AppBundle/Resources/config/validation.xml中發佈的代碼 但是,我收到以下錯誤: [錯誤1845]元素的屬性:沒有匹配的全局聲明可用於驗證根。 (in/sites/zioo/www/web/- 第1行第0列) 這是因爲我使用了yml嗎?我不確定。 –

+0

@MarcoKoopman你只需要在你的註釋中添加驗證組 – lordrhodos

+0

不確定你是什麼意思,如果它是因爲你使用yml而引起的。你必須添加的唯一東西是註釋部分* groups = {「ResetPassword」} –

0

兩個

/** 
* @Assert\Regex(
* pattern="/(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).{7,}/", 
* message="Uw wachtwoord moet zeven tekens of langer zijn, minimaal één getal bevatten, een hoofletter en een kleine letter. " 
*) 
*/ 
protected $plainPassword; 

而且

<property name="plainPassword"> 
    <constraint name="NotBlank"> 
     <option name="message">fos_user.password.blank</option> 
     <option name="groups"> 
      <value>Registration</value> 
      <value>ResetPassword</value> 
      <value>ChangePassword</value> 
     </option> 
    </constraint> 
    <constraint name="Length"> 
     <option name="min">2</option> 
     <option name="max">4096</option> 
     <option name="minMessage">fos_user.password.short</option> 
     <option name="groups"> 
      <value>Registration</value> 
      <value>Profile</value> 
      <value>ResetPassword</value> 
      <value>ChangePassword</value> 
     </option> 
    </constraint> 
</property> 

威爾的工作。錯誤來自我很久以前做出的驗證器文件。這個驗證器有一個錯誤,這個錯誤是這個選項無效的原因。

通過添加「* groups = {」registration「}」我修復了錯誤。

如果你跟我一樣檢查同樣的錯誤檢查你的驗證文件的錯誤並修復它們。