Example #1
0
function register($username, $name, $email, $password)
{
    global $TLD, $tld_db;
    show_header();
    /* prepare clean data */
    $username = htmlspecialchars(stripslashes($username));
    $password = htmlspecialchars(stripslashes($password));
    $name = htmlspecialchars(stripslashes($name));
    $email = htmlspecialchars(stripslashes($email));
    /* perform validation checks */
    if (filter_var($email, FILTER_VALIDATE_EMAIL) == FALSE) {
        echo "Not a valid email address";
        die;
    }
    $username = clean_up_input($username);
    /* just in case */
    $username = strtolower($username);
    if (username_taken($username)) {
        echo "That username is already taken. Please try using another, different username.";
        die;
    }
    /* let the user know */
    echo "Creating new account for " . $name . " via " . $username . "<BR>\n";
    /* generate user verification key */
    $userkeyfile = "tmp/" . $username . ".ukf";
    // some environments does not allow execuion outside its boundaries even /tmp
    $fh = fopen($userkeyfile, 'w') or die("Can't create user key verification file. Please report this to the admin.");
    $userkey = unique_id(16);
    fwrite($fh, $userkey);
    fclose($fh);
    /* prepare account */
    $base = database_open_now($tld_db, 0666);
    $real_password = hash('sha256', $password);
    date_default_timezone_set('Australia/Brisbane');
    $registered = strftime('%Y-%m-%d');
    $query = "INSERT INTO users (username, password, name, email, registered, verified)\n\t\t\tVALUES('" . $username . "', '" . $real_password . "', '" . $name . "', '" . $email . "', '" . $registered . "', 0)";
    $results = database_query_now($base, $query);
    /* construct email */
    $msg_FROM = "FROM: hostmaster@opennic." . $TLD;
    $msg_subject = "OpenNIC " . $TLD . " User Registration.";
    $msg = "Welcome " . $name . " to OpenNIC." . $TLD . "!\n\n";
    $msg .= "Your details are:\n";
    $msg .= "Username: "******"\n";
    $msg .= "Password: (The one you specified during sign up. Remember, this is encrypted and cannot be retrieved.)\n\n";
    $msg .= "Always ensure your contact details are up to date.\n\n";
    $msg .= "To confirm this email and activate your account, please visit http://opennic." . $TLD . "/confirm.php?username="******"&userkey=" . $userkey . "\nYou have 24 hours to activate your account, otherwise it will be deleted.\n\n";
    $msg .= "Thank you for your patronage.\nOpenNIC" . $TLD . " Administration.\n";
    mail($email, $msg_subject, $msg, $msg_FROM);
    echo "If registration was successful, you should receive an email shortly. Please contact hostmaster@opennic." . $TLD . " if you do not receive one within 24 hours. Please ensure that email address is on your email whitelist.";
    // echo "DEBUG: [".$msg."]";
}
Example #2
0
/*
   MUD4TLD - Martin's User and Domain system for Top Level Domains.
   Written 2012-2014 By Martin COLEMAN.
   This software is hereby dedicated to the public domain.
   Made for the OpenNIC Project.
   http://www.mchomenet.info/mud4tld.html
*/
include "conf.php";
if (isset($_REQUEST['username'])) {
    $username = $_REQUEST['username'];
    if (isset($_REQUEST['userkey'])) {
        $userkey = $_REQUEST['userkey'];
    } else {
        die("Userkey required.");
    }
    $clean_username = clean_up_input($username);
    if (username_taken($clean_username) == 0) {
        show_header();
        echo "Sorry, that username does not exist.\n";
        echo "</body></html>\n";
        die;
    }
    $myFile = "tmp/" . $clean_username . ".ukf";
    $fh = fopen($myFile, 'r') or die("Can't open user key verification.");
    $theData = fread($fh, filesize($myFile));
    fclose($fh);
    if ($theData != $userkey) {
        die("Invalid user key.");
    }
    unlink($myFile);
    confirm_user($clean_username);