Changeset 3627:9bccfc2257ad for inc/core/class.dc.auth.php
- Timestamp:
- 12/19/17 17:27:59 (8 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/core/class.dc.auth.php
r3535 r3627 121 121 if ($pwd != '') 122 122 { 123 if ($this->crypt($pwd) != $rs->user_pwd) { 124 sleep(rand(2,5)); 125 return false; 123 $rehash = false; 124 if (password_verify($pwd,$rs->user_pwd)) { 125 // User password ok 126 if (password_needs_rehash($rs->user_pwd,PASSWORD_DEFAULT)) { 127 $rs->user_pwd = $this->crypt($pwd); 128 $rehash = true; 129 } 130 } else { 131 // Check if pwd still stored in old fashion way 132 $ret = password_get_info($rs->user_pwd); 133 if (is_array($ret) && isset($ret['algo']) && $ret['algo'] == 0) { 134 // hash not done with password_hash() function, check by old fashion way 135 if (crypt::hmac(DC_MASTER_KEY,$pwd,DC_CRYPT_ALGO) == $rs->user_pwd) { 136 // Password Ok, need to store it in new fashion way 137 $rs->user_pwd = $this->crypt($pwd); 138 $rehash = true; 139 } else { 140 // Password KO 141 sleep(rand(2,5)); 142 return false; 143 } 144 } else { 145 // Password KO 146 sleep(rand(2,5)); 147 return false; 148 } 149 } 150 if ($rehash) { 151 // Store new hash in DB 152 $cur = $this->con->openCursor($this->user_table); 153 $cur->user_pwd = (string) $rs->user_pwd; 154 $cur->update("WHERE user_id = '".$rs->user_id."'"); 126 155 } 127 156 } 128 157 elseif ($user_key != '') 129 158 { 130 if (http::browserUID(DC_MASTER_KEY.$rs->user_id.$ rs->user_pwd) != $user_key) {159 if (http::browserUID(DC_MASTER_KEY.$rs->user_id.$this->cryptLegacy($rs->user_id)) != $user_key) { 131 160 return false; 132 161 } … … 172 201 public function crypt($pwd) 173 202 { 203 return password_hash($pwd,PASSWORD_DEFAULT); 204 } 205 206 /** 207 * This method crypt given string (password, session_id, …). 208 * 209 * @param string $pwd string to be crypted 210 * @return string crypted value 211 */ 212 public function cryptLegacy($pwd) 213 { 174 214 return crypt::hmac(DC_MASTER_KEY,$pwd,DC_CRYPT_ALGO); 175 215 } … … 184 224 { 185 225 if (!empty($this->user_info['user_pwd'])) { 186 return $pwd == $this->user_info['user_pwd'];226 return password_verify($pwd,$this->user_info['user_pwd']); 187 227 } 188 228
Note: See TracChangeset
for help on using the changeset viewer.