Files
tougao/application/api/controller/EmailService.php
wangjinlei 1f7220f36e 1
2024-08-07 15:02:14 +08:00

46 lines
1.1 KiB
PHP

<?php
namespace app\api\controller;
use app\api\controller\Base;
use think\Db;
use think\Queue;
use think\Env;
use think\Validate;
class EmailService extends Base
{
public function __construct(\think\Request $request = null)
{
parent::__construct($request);
}
public function refusePassword()
{
$data = $this->request->post();
$rule = new Validate([
"password" => "require"
]);
if (!$rule->check($data)) {
return jsonError($rule->getError());
}
$password = $data['password'];
if (function_exists('openssl_random_pseudo_bytes')) {
$salt = substr(str_replace('+', '.', base64_encode(openssl_random_pseudo_bytes(6))), 0, 8);
} else {
// 使用 mt_rand 作为后备方法
$salt = '';
for ($i = 0; $i < 8; $i++) {
$salt .= chr(mt_rand(33, 126)); // 生成随机字符
}
}
$hashed_password = crypt($password, '$1$' . $salt . '$');
return jsonSuccess(["result"=>$hashed_password]);
// return $hashed_password;
}
}