【问题标题】:Check password strength - Uncaught ArgumentCountError: Too few arguments to function检查密码强度 - Uncaught ArgumentCountError: Too little arguments to function
【发布时间】: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 = "密码很强大,可以在这里继续解析。"; } }

标签: php passwords


【解决方案1】:

strongpass->check('asdgasdfsadfasd') 看起来您只是将 $password 传递给 check 方法,而没有传递 $user

【讨论】:

    【解决方案2】:

    您定义了需要 $password$user 参数的方法:

    public function check($password,$user){
    

    但你只传$password:

    $response = $strongpass->check($password);
    

    所以也传递$user

    $response = $strongpass->check($password, $user);
    

    但是,我不知道它会如何工作:

    $password = "";
    $status = ""; 
    $user = "";
    

    【讨论】:

    • 我不确定它是如何工作的,因为我正在关注 youtube 教程..
    • 如果那是他们提供的代码,请不要使用该教程。
    • 我明白了,您对此有什么建议吗?我必须做一个密码强度检查器,它还检查不包含字典单词的密码
    • 我已经完成了长度、大写、小写和数字。只需要2个
    猜你喜欢
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-26
    • 2014-10-26
    • 2012-06-16
    • 1970-01-01
    相关资源
    最近更新 更多