This commit is contained in:
wangjinlei
2024-08-07 15:02:14 +08:00
parent c57077e35f
commit 1f7220f36e
6 changed files with 179 additions and 23 deletions

View File

@@ -0,0 +1,46 @@
<?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;
}
}