【发布时间】:2021-05-19 15:32:15
【问题描述】:
如何检查我的 PHP 代码的密码强度?它显示此错误消息:
致命错误:未捕获的 ArgumentCountError:函数 strongpass::check() 的参数太少,1 在第 8 行的 C:\newxampp\htdocs\fyp\index.php 中传递,而在 C:\newxampp\htdocs 中恰好有 2 \fyp\strongpass.php:7 堆栈跟踪:#0 C:\newxampp\htdocs\fyp\index.php(8): strongpass->check('asdgasdfsadfasd') #1 {main} throw in C:\newxampp\ htdocs\fyp\strongpass.php 在第 7 行
class strongpass{
public function check($password,$user){
$denum_pass = strtr($password,'5301!','seoll');
$word_file = '/usr/share/dict/words'; // here is my dictionary
$lc_user = strtolower($user);
$lc_pass = strtolower($password);
$response = "OK";
//password that can't be same as username or reversed username
else if (($user == $password) || ($password == strrev($user))||
(denum_pass == $user) || ($denum_pass == strrev($user))){
$response = " Password cannot be same with username.";}
//password that doesn't contain any word in dictionary
else if (is_readable($word_file)){
if ($fh = fopen($word_file,'r')){
$found = false;
while (! ($found || feof($fh))) {
$word = preg_quote(trim(strtolower(fgets($fh,1024))),'/');
if (preg_match("/$word/",$lc_pass) || preg_match("/$word/",$denum_pass)){
$found = true;}}
fclose($fh);
if ($found){
$response = 'Password is based on a dictionary word.';}}}
return $response; } }
类是这样使用的:
$user = ""; if(isset($_POST["password"])){
$password = $_POST["password"];
include_once("strongpass.php");
$strongpass = new strongpass();
$response = $strongpass->check($password);
if($response != "OK"){
$status = $response;
} else {
$status = "Password is strong so parsing can continue here.";
}
【问题讨论】:
-
else if (($user == $password)你是从else if开始的吗?if在哪里? (好的代码缩进也很好) -
错误是不言自明的,显示你如何调用这个函数。修复后会有其他错误。
-
@brombeer 我实际上是从 IF 开始的,有些部分是代码无法运行的
-
@AbraCadaver 喜欢这样吗? $密码 = ""; $状态 = ""; $用户 = ""; if(isset($_POST["password"])){ $password = $_POST["password"]; include_once("strongpass.php"); $strongpass = 新的strongpass(); $response = $strongpass->check($password); if($response != "OK"){ $status = $response; } else { $status = "密码很强大,可以在这里继续解析。"; } }