Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @author Linkero
- * @copyright 2010
- */
- class login
- {
- private $username;
- private $password;
- private $auth;
- public function beginLogin()
- {
- $regex = "@[^a-zA-Z0-9_-]+@i";
- if (!preg_match($regex, $_POST['username'])) {
- if (isset($_POST['login'])) {
- $username = $_POST['username'];
- if (strlen($username) < 3 || strlen($username) > 20) {
- echo "Username has to be between 3 and 20 characters";
- } else {
- login::checkPassword($_POST);
- }
- }
- } else {
- echo "Username contains invalid characters.";
- }
- }
- private function checkPassword($_POST)
- {
- $password = $_POST['password'];
- if (strlen($password) < 6 || strlen($password) > 20) {
- echo "Password has to be between 6 and 20 characters";
- } else {
- login::checkDBPassword($_POST);
- }
- }
- private function checkDBPassword($_POST)
- {
- $query = 'SELECT * FROM users WHERE member_name = "' . $_POST['username'] . '"';
- $result = mysql_query($query) or die('Query failed: ' . mysql_error());
- $auth = mysql_fetch_assoc($result) or die('Query failed: ' . mysql_error());
- $dbmd5 = $auth['md5'];
- $usermd5 = md5(base64_encode(md5(base64_encode($_POST['password']))));
- if ($usermd5 != $dbmd5) {
- echo "Invalid password. Try again.<br>";
- } else {
- login::setSession($auth, $_POST);
- }
- }
- private function setSession($auth, $_POST)
- {
- $_SESSION['username'] = $auth['member_name'];
- $_SESSION['md5'] = $auth['md5'];
- $_SESSION['scroll'] = $auth['scroll'];
- $_SESSION['mid'] = $auth['member_id'];
- $_SESSION['gid'] = $auth['group_id'];
- login::lastStep();
- }
- private function lastStep()
- {
- echo "Login Successful!";
- echo '<script type="text/javascript">function goHome(){if (window.top!=window.self){window.top.location="index.php"}}</script>';
- echo '<input type="button" onclick="goHome()" value="Click here to finish login!">';
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement