Update password in backend in yii2
<p>I did CRUD in Yii2 Advanced- backend. I used class extend ActiveRecord. And I have a problem with the password attribute, when I want to update it displays the hashed password with a lot of dots, when I try to update it doesn't save the hashed password. So I used beforeSave to hash my password:</p>

<pre><code>public function beforeSave($insert)
{
    if (parent::beforeSave($insert)) {
        if($this-&gt;isNewRecord) {
            $this-&gt;created_at = time();
            $this-&gt;status = self::DEFAULT_STATUS;
            $this-&gt;generateAuthKey();
            $this-&gt;setPassword($this-&gt;PasswordHash);
            $this-&gt;RulesAccept=1;
            return true;
        } else {
            $this-&gt;setPassword($this-&gt;PasswordHash);
            return true;
        }
    } 
}
</code></pre>

<p>I dont know how can I do that when I displayed the updating form it display me dots from hashed password and if you do not change the password also will not change. Currently, and each time you click Update my password is changed or re-hashing. How can I avoid this. I trying to use empty value in form like this:</p>

<pre><code>&lt;label class="control-label"&gt; &lt;?= Yii::t('app', 'Hasło')?&gt; &lt;/label&gt;
&lt;?= $form-&gt;field($model, 'PasswordHash')-&gt;passwordInput(['placeholder' =&gt; Yii::t('app', 'Utwórz hasło'), 'value' =&gt; ''])-&gt;label('') ?&gt;
</code></pre>

<p>And then i tried to check in my beforeSave() if input form was empty then does not save this password just leave it as it is in the database:</p>

<pre><code>public function beforeSave($insert)
{
    if (parent::beforeSave($insert)) {
        if($this-&gt;isNewRecord) {
            $this-&gt;created_at = time();
            $this-&gt;status = self::DEFAULT_STATUS;
            $this-&gt;generateAuthKey();
            $this-&gt;setPassword($this-&gt;PasswordHash);
            $this-&gt;RulesAccept = 1;
            return true;
        } else {
            if((!empty)$this-&gt;PasswordHash)){
                $this-&gt;setPassword($this-&gt;PasswordHash);
                return true;
            }
            return false;
        }
    } 
}
</code></pre>

<p>So always when i come in the form of update i see empty input of password. And if i dont wrote new passwort it change only all attributes which i changed, but if i wrote some password it save me this new password. I think this function should work that but i wrong and this form always change password. What can i do to fix that. Maybe there is some other way? </p>