PHP Read txt file and check if username password exists

前端 未结 3 725
一个人的身影
一个人的身影 2021-01-29 14:12

I have a bunch of passwords and usernames stored in a txt file and i need to check for matches. I know this is not a safe method but its for leaning purposes.

This code

3条回答
  •  無奈伤痛
    2021-01-29 14:35

    Consider the possibility of having a space in the password so as any symbols. Perhaps you should split on a line break ("\n").

    if( $result[$i] === $user && $result[$i+1] === $password )
    

    The first part of the statement has to be true for the second one to be evaluated. The $i variable is never changed

    $file = "username1 passwords1 username2 password2";
    $result = explode(" ",$file);
    $user = "username1";
    $password = "passwords1";
    
    for($i=0; $i< count($result); $i++){
    
        if($result[$i] === $user && $result[$i+1] === $password)
        {
    
            echo 'Password and Username Correct';
       }
    }
    

提交回复
热议问题