私は何か特定のことをしようとしています。配列の各要素のユーザー名とパスワードを比較して、既存のユーザーと一致するものを見つける必要があります。
2 つの配列があります。すべてのユーザー情報を含む 1 つ。もう 1 つはログイン試行を含むものです。演習は、ログイン試行が一致した場合にユーザー情報を出力することです。したがって、$loginInfo と $userData を比較して、保存されているユーザー名とパスワードと一致するログイン試行があるかどうかを確認する必要があります。
この演習では、substr()、md5()、および strtolower() も使用する必要があります。ユーザー名は大文字と小文字が区別されませんが、パスワードは大文字と小文字が区別されます。これをどのように行うべきかわかりませんが、ユーザー名に strtolower() を使用できますが、md5 ハッシュの最後の 8 文字も探しています。私もこれを行う方法がわからない。パスワード ハッシュの最後の 8 文字をログイン試行ハッシュと比較しています。
これは、助けようとするすべての人にとって混乱を招くと思います。それは明らかに私を混乱させています。
これをより理解するのに役立つことを願って、コードを添付しています。
ありがとうございます!
<?php
$userData = array();
$userData[] = array(
'Name' => 'Joe Banks',
'Acct' => '12345',
'Email' => 'joe@home.com',
'UserName' => 'Joe',
'Password' => '8e549b63',
'Active' => false);
'Password' => 'Password1'
$userData[] = array(
'Name' => 'Polly Cartwrite',
'Acct' => '34567',
'Email' => 'polly@yahoo.com',
'UserName' => 'PCart',
'Password' => '91f84e7b',
'Active' => true);
'Password' => '12345'
$userData[] = array(
'Name' => 'Jake Jarvis',
'Acct' => '81812',
'Email' => 'jjar@gmail.com',
'UserName' => 'jakej',
'Password' => 'd5cc072e',
'Active' => true);
'Password' => 'LetMeIn'
$userData[] = array(
'Name' => 'Kelly Williams',
'Acct' => '76253',
'Email' => 'kw1234@yahoo.com',
'UserName' => 'kellyw',
'Password' => '2d635fc7',
'Active' => false);
'Password' => 'Kelly'
$userData[] = array(
'Name' => 'Cindy Ella',
'Acct' => '62341',
'Email' => 'washgirl@momsplace.com',
'UserName' => 'Cinders',
'Password' => '87c0e367',
'Active' => true);
'Password' => '9Kut!5pw'
// The loginInfo array contains a series of login attempts. Each attempt
// is composed of a username and password
$loginInfo = array();
$loginInfo[] = array('joe','hello');
$loginInfo[] = array('PCART','12345');
$loginInfo[] = array('jakej','letmein');
$loginInfo[] = array('KellyW','Kelly');
$loginInfo[] = array('Cinder','9Kut!5pw');
// function printUser()
// inputs:
// $user - an array containing the user's data. The expectation is that
// this array will contain the user's name, password, username,
// active status, account number and email address
// outputs:
// n/a
// This function will print out all of the information for a particular
// user in tabular format (with the exception of the password which will
// be suppressed).
function printUser($user) {
// Each user will be printed in its own row in the table
echo "<div class='tablerow'>\n";
foreach ($user as $index => $item) {
// suppress printing the password
if ($index == "Password")
continue;
// pretty print the user's status
if ($index == "Active") {
if ($item) {
$item = "active";
} else {
$item = "inactive";
}
}
// print the data in a tabledata box
echo "<div class='tabledata'>$item</div>\n";
}
// end the row
echo "</div>\n";
}
function checkLogin($loginInfo){
global $userData;
foreach($userData as $attempt) {
if($loginInfo[$attempt][0] == $userData['UserName']){
if($loginInfo[$attempt][1] == $userData['Password']){
printUser($userData);
}
}
}
}
checkLogin($loginInfo);
?>