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; } }