예제 #1
0
if (isset($_POST['submit'])) {
    isset($_POST['firstname']) ? $firstname = $_POST['firstname'] : ($firstname = "");
    isset($_POST['lastname']) ? $lastname = $_POST['lastname'] : ($lastname = "");
    isset($_POST['email']) ? $email = $_POST['email'] : ($email = "");
    $captchaKey = substr($_SESSION['key'], 0, 5);
    $formKey = $_POST['formKey'];
    if ($formKey == $captchaKey) {
        if ($firstname && $lastname) {
            include_once 'DB.php';
            $dbConnectString = $configValues['CONFIG_DB_ENGINE'] . "://" . $configValues['CONFIG_DB_USER'] . ":" . $configValues['CONFIG_DB_PASS'] . "@" . $configValues['CONFIG_DB_HOST'] . "/" . $configValues['CONFIG_DB_NAME'];
            $dbSocket = DB::connect($dbConnectString);
            /* let's generate a random username and password
               of length 4 and with username prefix 'guest' */
            $rand = randomAlphanumeric(4);
            $username = $usernamePrefix . $rand;
            $password = randomAlphanumeric(4);
            /* adding the user to the radcheck table */
            $sql = "INSERT INTO radcheck values (0, '{$username}', 'User-Password', '==', '{$password}')";
            $res = $dbSocket->query($sql);
            /* adding user information to the userinfo table */
            $sql = "INSERT INTO userinfo (username, firstname, lastname, email) values " . "('{$username}', '{$firstname}', '{$lastname}', '{$email}')";
            $res = $dbSocket->query($sql);
            /* adding the user to the default group defined */
            $sql = "INSERT INTO usergroup values ('{$username}', '" . $configValues['CONFIG_GROUP_NAME'] . "', '" . $configValues['CONFIG_GROUP_PRIORITY'] . "')";
            $res = $dbSocket->query($sql);
            echo "<br/><br/>\n\t                                Welcome " . $_POST['firstname'] . ",<br/>" . "Your username is: {$username} <br/>and your password is: {$password} <br/>";
            $dbSocket->disconnect();
            exit;
        } else {
            echo "<br/><br/>\n                                Please fill in your first and last name <br/>";
            exit;
예제 #2
0
session_start();
function randomAlphanumeric($length)
{
    $chars = "abcdefghijkmnpqrstwxyz23456789ABCDEFGHKLMNPQRSTVWXYZ";
    srand((double) microtime() * 1000000);
    $i = 0;
    $pass = '';
    while ($i <= $length - 1) {
        $num = rand() % 33;
        $tmp = substr($chars, $num, 1);
        $pass = $pass . $tmp;
        $i++;
    }
    return $pass;
}
$ResultStr = randomAlphanumeric(5);
$NewImage = imagecreatefromjpeg("captcha.jpg");
//image create by existing image and as back ground
$LineColor = imagecolorallocate($NewImage, 233, 239, 239);
//line color
$TextColor = imagecolorallocate($NewImage, 255, 255, 255);
//text color-white
imageline($NewImage, 1, 1, 40, 40, $LineColor);
//create line 1 on image
imageline($NewImage, 1, 100, 60, 0, $LineColor);
//create line 2 on image
imagestring($NewImage, 5, 20, 10, $ResultStr, $TextColor);
// Draw a random string horizontally
$_SESSION['key'] = $ResultStr;
// carry the data through session
header("Content-type: image/jpeg");