Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PHP/AJAX Login taking very long
- <form name="login-form" onsubmit="return false">
- <input type="text" id="the_username" value="Username" onfocus="emptyUsername(this);" onblur="clickrecall(this,'Username')" class="focusfield input push" />
- <input type="password" id="the_password" value="Password" class="input" onfocus="emptyPassword(this);" onblur="clickrecall(this,'Password')" />
- <span id="dialog-login-fail" title="Login failed"></span>
- <input type="submit" onclick="javascript:void(0);" id="loginBtnBre" class="sign-in signin-submit-btn" value="Login Now" />
- </form>
- <?php
- require 'config.inc.php';
- foreach($_POST as $k=>$v)
- {
- $_POST[$k] = trim($v);
- }
- if(!isset($_POST['theusername']) or !isset($_POST['thepassword']))
- {
- print "Please use all fields";
- }elseif(empty($_POST['theusername'])){
- print "Please enter a username";
- }elseif(empty($_POST['thepassword'])){
- print "Please enter a password";
- }elseif($_POST['theusername'] == "username" && $_POST['thepassword'] == "password")
- {
- print "Password & User cannot be the ones already listed";
- }elseif(!preg_match("/^[a-z0-9]+$/i", $_POST['theusername']))
- {
- print "Please use only characters and numbers for username, no spaces, dashes or others!";
- }else{
- $password = md5($_POST['thepassword']);
- $user = $_POST['theusername'];
- $loginVar = $usersClass->login($user, $password);
- if(is_array($loginVar))
- {
- $_SESSION['loggedIn'] = $loginVar;
- @session_regenerate_id(true);
- print "success";
- }else{
- print "Whoops, something went wrong! Try again.";
- }
- }
- ?>
- public function login($username, $password)
- {
- $rs = mysql_query("SELECT `id`,`active` from `$this->usersTable` WHERE
- `username` = '".mysql_real_escape_string($username)."' AND
- `password` = '".mysql_real_escape_string($password)."'");
- if($rs) {
- $row = @mysql_fetch_object($rs);
- return $this->userInfo($row->id);
- }else{
- return false;
- }
- alter table `TableName` add index `username` (`username`(500));
- alter table `TableName` add index `password` (`password`(500));
Add Comment
Please, Sign In to add comment