title: PHP Yii2 Password Encryption
body: <p>Need help because i'm still new to Yii2. I want to encrypt the password before saving it to the database. So i'm using <strong>sha1</strong> but the problem is that the password field in the form has contents when i apply this line of code in the controller shown below.</p>
  
  <blockquote>
    <p>$model->password = sha1($model->attributes['password']);</p>
  </blockquote>
  
  <p><strong>This is the Controller create method:</strong></p>
  
  <pre><code>public function actionCreate()
  {
      $model = new Employeeinformation();
  
      //$model-&gt;password = sha1($model-&gt;attributes['password']);
  
      $model-&gt;created_date = date('Y-m-d H:i:s');
  
      if ($model-&gt;load(Yii::$app-&gt;request-&gt;post()) &amp;&amp; $model-&gt;save()) {
          return $this-&gt;redirect(['view', 'id' =&gt; $model-&gt;employee_id]);
      } else {
          return $this-&gt;render('create', [
              'model' =&gt; $model,
          ]);
      }
  }
  </code></pre>
  
  <p><strong>This is the form:</strong></p>
  
  <pre><code>&lt;div class="employeeinformation-form"&gt;
  
  &lt;?php $form = ActiveForm::begin(); ?&gt;
  
  &lt;?= $form-&gt;field($model, 'employee_id')-&gt;textInput(['minlength' =&gt; true, 'maxlength' =&gt; true]) ?&gt;
  
  &lt;?= $form-&gt;field($model, 'password')-&gt;passwordInput(['maxlength' =&gt; true]) ?&gt;
  
  &lt;?= $form-&gt;field($model, 'last_name')-&gt;textInput(['maxlength' =&gt; true]) ?&gt;
  
  &lt;?= $form-&gt;field($model, 'first_name')-&gt;textInput(['maxlength' =&gt; true]) ?&gt;
  
  &lt;?= $form-&gt;field($model, 'hired_date')-&gt;widget(\yii\jui\DatePicker::classname(), [
      'language' =&gt; 'en',
      'dateFormat' =&gt; 'yyyy-MM-dd',
  ]) ?&gt;
  
  
  
  &lt;div class="form-group"&gt;
      &lt;?= Html::submitButton($model-&gt;isNewRecord ? 'Create' : 'Update', ['class' =&gt; $model-&gt;isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?&gt;
  &lt;/div&gt;
  
  &lt;?php ActiveForm::end(); ?&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>Screenshot of my problem:</strong></p>
  
  <blockquote>
    <p><a href="http://i.imgur.com/YTDW1Ud.png" rel="nofollow">http://i.imgur.com/YTDW1Ud.png</a></p>
  </blockquote>
  
  <p>Thank you in advance.</p>