public static function authenticate($username, $password) { Log::info('HackableUser', sprintf('Authenticate user: "******"', $username)); $salt = self::retrieve_salt($username); Log::debug('HackableUser', sprintf('Salt: "%s"', $salt)); $hashed_password = self::generate_hash($password, $salt); try { $user = self::retrieve($username, $hashed_password); } catch (\Lib\Exceptions\NotFoundException $e) { Log::info('User', sprintf('User not found: "%s"', $username)); throw new \Lib\Exceptions\UnauthorizedException(); } $user->create_token(); return $user; }
public static function authenticate($username, $password) { Log::info('User', sprintf('Authenticate user: "******"', $username)); try { $user = self::retrieve($username); } catch (\Lib\Exceptions\NotFoundException $e) { Log::info('User', sprintf('User not found: "%s"', $username)); throw new \Lib\Exceptions\UnauthorizedException(); } $hashed_password = self::generate_hash($password, $user->salt); if ($user->password !== $hashed_password) { Log::info('User', sprintf('Password does not match for user: "******"', $username)); throw new \Lib\Exceptions\UnauthorizedException(); } $user->create_token(); return $user; }
/** * 图片缩略 * @param array $attach_info 附件信息 * @return array / boolean 缩略图集合或者false * @author 李志亮 <*****@*****.**> */ public static function createThumb($attach_info) { $attach_info['path'] = preg_replace('/\\/|\\\\/', DIRECTORY_SEPARATOR, $attach_info["path"]); try { $thumbs = array(); $image = new \Think\Image(1, UPLOAD_PATH . $attach_info['path']); foreach (static::$thumbs as $key => $thumb) { $thumb_url = str_replace('.' . $attach_info['ext'], $thumb['w'] . 'x' . $thumb['h'] . '.' . $attach_info['ext'], $attach_info['url']); $thumb_path = UPLOAD_PATH . str_replace('.' . $attach_info['ext'], $thumb['w'] . 'x' . $thumb['h'] . '.' . $attach_info['ext'], $attach_info['path']); $image->thumb($thumb['w'], $thumb['h'], \Think\Image::IMAGE_THUMB_FILLED)->save($thumb_path); $thumbs[$thumb['w'] . 'x' . $thumb['h']] = $thumb_url; } return $thumbs; } catch (Exception $e) { $result['message'] = $e->getMessage(); Log::info('缩略图生成失败; ' . json_encode($attach_info) . '; ' . $e->getMessage()); } }