How can we encrypt the username and password using PHP?How can we destroy the session, how can we unset the variable of a session? ~ Interview Questions & Answers

Monday, March 3, 2008

How can we encrypt the username and password using PHP?

User names and passwords in PHP can be encrypted using md5 function.
MD5 function calculates the md5 hash of a string. It is basically used for encryption. It is also used for digital signature applications, where a large file must be "compressed" in a secure manner.
Example:
Md5($str);
Crypt() function can also be used to encrypt a string,. It used MD5, DES or blow fish algorithms for encryption.
Syntax:
Crypt(str, salt)
Salt is an optional parameter used to increase the number of characters encoded, to make the encoding more secure

How can we destroy the session, how can we unset the variable of a session?

session_unset() function frees all session variables currently registered.
If $_SESSION (or $HTTP_SESSION_VARS for PHP 4.0.6 or less) is used, use unset() to unregister a session variable.
i.e. unset ($_SESSION['varname']);.