it is for a single user. the two values you speak of are already known and static values in the php class. it will be more difficult to change them, but the information behind the login isn't important enough to justify ssl/tls.
/*
* this class is for a simple cookie login function
*
* All methods are static and can be accessed without instantiating the class. This class works
* by first sending a cookie with an encrypted string to the browser. The browser then decrypts
* the string, removes the salt, encrypts the remainder, and sends it back to the server with
* the cookie. Finally the login() function is called to decrypt and test the strings for addition
* to the session register.
*
* --- Method list ---
*
* static login()
* static checkLoginStatus()
* static setLoginCookie()
* static genRandomString()
* static salt()
* static skey()
*
*/
include('DESCryptography.php');
class SimpleLogin {
private static $salt='username'; // define the salt for the encrypted string
private static $skey='password'; // define the key for encryption
// ---- DO NOT EDIT BELOW THIS LINE ---- //
public static function login($input) {
/* --- login() ---
* requires a browser cookie 'vuid'
* input variable needs to be an encrypted string using the DESCryptography.php script
*
* returns true with successful login and false when not
*
*/
$cookie = (isset($_COOKIE['vuid'])) ? $_COOKIE['vuid'] : '';
$passphrase=str_replace(self::$salt,'',des(self::$skey,hexToString($cookie),0,0,null));
$comp=des(self::$skey,hexToString($input),0,0,null);
if(strcmp(trim($comp), trim($passphrase)) == 0){
session_register($passphrase);
return true;
} else return false;
}
public static function checkLoginStatus() {
/* --- checkLoginStatus() ---
* This function checks for a cookie 'vuid', decrypts the string, removes the salt, and
* checks the remainder for existence in the session register.
*
* Returns false with no cookie, true for registered session, and false for non-registered
* session.
*
*/
$cookie=(isset($_COOKIE['vuid'])) ? $_COOKIE['vuid'] : '';
if($cookie){
$passphrase=str_replace(self::$salt,'',des(self::$skey,hexToString($cookie),0,0,null));
if(!session_is_registered($passphrase)) {
return false;
} else return true;
} else return false;
}
public static function setLoginCookie() {
/* --- setLoginCookie() ---
* Creates an encrypted string with the key from a random string and the salt and sets it
* in a cookie. This method may not work when used from this class.
*
*/
$code=self::genRandomString();
$message=$code.self::$salt;
$cyphertext=hexToString(des(self::$skey,$message,1,0,null));
setcookie('vuid',stringToHex($cyphertext));
}
public static function genRandomString() {
/* --- genRandomString() ---
* Generates a random string 'len' digits long.
*
*/
$len=8;
$chars='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$str='';
for($i=0;$i<$len;$i++){
$str.=$chars[mt_rand(0,strlen($chars))];
}
return $str;
}
public static function salt() {
return self::$salt;
}
public static function skey() {
return self::$skey;
}
}