<?php Echo $____________________ if ($code==\"test\") echo \"correct code\"; els
ID: 3575294 • Letter: #
Question
<?php
Echo $____________________
if ($code=="test")
echo "correct code";
else
echo "wrong code";
The admin’s passcode is given in plain text in the above php program, and it can be seen by anyone who can access this program. A simple (but still not a good) solution is using md5 hash function. The md5 hash of the text “test” (without quotations) is assigned to a constant $codeH. Fill in the blank in the if statement below to verify whether the given passcode is “test” (but, the
text “test” should not be included in the program as plain text)
$codeH = “098f6bcd4621d373cade4e832627b4f6” // md5 hash of the passcode
if ( ___________________________ )
echo "correct code";
else
echo "wrong code";
Explanation / Answer
An md5 function will convert a plain text into its md5 hash version of a passcode. Therefore, once the passcode is given by the user, it will be compared with the md5 version of the actual passcode.
So, the code to be filled here is:
$codeH = “098f6bcd4621d373cade4e832627b4f6” // md5 hash of the passcode
if ( md5($code) == $codeH )
echo "correct code";
else
echo "wrong code";
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.