<?php
 
/************************************************************* 
 
 * This script is developed by Arturs Sosins aka ar2rsawseen, http://webcodingeasy.com 
 
 * Feel free to distribute and modify code, but keep reference to its creator 
 
 * 
 
 * Inkblot auth class allows to implement inkblot authentication to your PHP application.
 
 * It can generate list of inkblots from directory or array.
 
 * User may provide amount of letters saved per inkblot, to implement different
 
 * password generation ways
 
 * 
 
 * For more information, examples and online documentation visit:  
 
 * http://webcodingeasy.com/PHP-classes/Inkblot-authentication
 
**************************************************************/
 
session_start();
 
include("./inkblot_auth.php");
 
//provide path to directory with inkblot images
 
$ink = new inkblot_auth("./inkblots");
 
 
if(isset($_SESSION["pass"]))
 
{
 
    //we already created pass for testing
 
    echo "<h3>You have successfully registered. Now try to login using same password</h3>";
 
    
 
    //first we need to provide password which we previously saved
 
    //usually it is retrieved form database using provided username
 
    //but for testing we've saved in in session variable
 
    $ink->set_pass($_SESSION["pass"]);
 
    
 
    if(isset($_POST["logpass"]))
 
    {
 
        //no we check user provided password
 
        //only after providing saved password
 
        if($ink->check_pass($_POST["logpass"]))
 
        {
 
            echo "<h3>You provided correct password</h3>";
 
        }
 
        else
 
        {
 
            echo "<h3>Your password is incorrect</h3>";
 
        }
 
    }
 
    
 
    //now we will get inkblots that were used in pasword
 
    $inks = $ink->get_inkblots();
 
    echo "<div style='overflow: auto; margin-bottom: 50px;'>";
 
    foreach($inks as $val)
 
    {
 
        echo "<img src='".$val."' 
 
            style='float: left; margin-right: 10px; width: 200px;'/>";
 
    }
 
    echo "</div>";
 
    echo "<p>All you have to do is remember your password while seeing same 
 
    inkblots, that you saw when you created this password.</p>
 
    <p>Just insert your first and last letter of your inkblot interpretations 
 
        in inkblot order (from left to right)</p>";
 
    echo "<form action='' method='post'>
 
    <p>Enter your saved password: <input type='text' name='logpass'/> 
 
    <input type='submit' value='Register'/></p>
 
    </form>";
 
}
 
else
 
{
 
    //someone submitted pass
 
    if(isset($_POST["regpass"]))
 
    {
 
        //get encoded pass and save it
 
        $_SESSION["pass"] = $ink->get_pass($_POST["regpass"]);
 
        //refresh page
 
        header("Location: ".$_SERVER["REQUEST_URI"]);
 
    }
 
    echo "<h3>Create new password (Simulating registration)</h3>";
 
    //no pass created
 
    $inks = $ink->get_inkblots();
 
    echo "<div style='overflow: auto; margin-bottom: 50px;'>";
 
    foreach($inks as $val)
 
    {
 
        echo "<img src='".$val."' 
 
            style='float: left; margin-right: 10px; width: 200px;'/>";
 
    }
 
    echo "</div>";
 
    echo "<p>This login is based on user choosing and remembering the password 
 
        based on inkblot that user see.</p>
 
<p>Because human mind interprets each inkblot differently, it means, that it is 
 
    possible that no one else will see a thing that you saw.</p>
 
<p>You must type first and last letter of each inkblot interpretation based on 
 
sequence you see those inkblots (from left to right)</p>
 
<p>Then each time you'll try to login, you'll see same inkblot images only each 
 
time in different order</p>
 
<p>Refresh page to change inkblots</p>";
 
    echo "<form action='' method='post'>
 
    <p>Enter your password: <input type='text' name='regpass'/> 
 
    <input type='submit' value='Register'/></p>
 
    </form>";
 
}
 
?>
 
 |