diff options
| author | Patrick Seeger <pseeger@ccwn.org> | 2012-05-20 16:58:26 +0200 |
|---|---|---|
| committer | Patrick Seeger <pseeger@ccwn.org> | 2012-05-20 16:58:26 +0200 |
| commit | 4f959ffc80e64dc9ee8383826a546723d97305d9 (patch) | |
| tree | 3a0704c0e3a9f44746739ccffa0d64acc5ab172d /protected/models/User.php | |
| parent | acec2b5dc35302147f9a9c73d837dce2f3f9958e (diff) | |
| parent | 9aad228e1af661b9b39df83700d27e71697dc66f (diff) | |
Merge branch 'master' of ssh://proxy.ccwn.org:9044/home/ccwn/git-repos/admin.astaf.de
Diffstat (limited to 'protected/models/User.php')
| -rw-r--r-- | protected/models/User.php | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/protected/models/User.php b/protected/models/User.php index b6a1609..e0a5eeb 100644 --- a/protected/models/User.php +++ b/protected/models/User.php @@ -79,6 +79,19 @@ class User extends CActiveRecord ); } + protected function beforeSave() { + if ($this->isNewRecord) { + $this->created_at = new CDbExpression("NOW()"); + $this->salt = $this->generateRandomKey(); + } + + if (!$this->checkPassword($this->password)) { + $this->password = $this->encryptPassword($this->password); + } + + return parent::beforeSave(); + } + /** * Retrieves a list of models based on the current search/filter conditions. * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. @@ -104,6 +117,21 @@ class User extends CActiveRecord } public function checkPassword($password) { - return sha1($this->salt.$password) == $this->password; + return $this->encryptPassword($password) == $this->password; } + + protected function encryptPassword($password) { + return sha1($this->salt.$password); + } + + protected function generateRandomKey($len = 20) {
+ $string = '';
+ $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
+ for ($i = 1; $i <= $len; $i++) {
+ $string .= substr($pool, rand(0, 61), 1);
+ }
+
+ return md5($string);
+ }
+ }
\ No newline at end of file |
