Jump to content

Recommended Posts

This is my login page code, and I want your opinion on it please! ;)

 

  // Login ~ CHECKS THE (USERNAME/PASSWORD) ENTERED BY THE USER THEN EITHER GRANTS ACCESS OR DENIEDS ACCESS
  case "Login":
    if(!preg_match("/^[a-z0-9]{2,20}$/i", $_POST["F_1_Login_Username"]) || !preg_match("/^[a-z0-9]{2,20}$/i", $_POST["F_1_Login_Password"])){
  $Login_Error = "INCORRECT ACCOUNT INFORMATION";
}
if(!$Login_Error){
      $Login_Username = $DB->real_escape_string($_POST["F_1_Login_Username"]);
      $Login_Password = $DB->real_escape_string(md5($_POST["F_1_Login_Password"]));
      $Login_Check = $DB->query("SELECT id,username,account_status,suspended_timestamp FROM members WHERE username='$Login_Username' && password='$Login_Password'");
      $Login_Status = $Login_Check->num_rows;
      $Login_Information = $Login_Check->fetch_object();
      if($Login_Status){
        if($Login_Information->account_status == 0){
          if(!QUICK_STATUS_CHECK($DB,$Login_Information->id,$TIMESTAMP)){
            $_SESSION["USER_ID"] = $Login_Information->id;
            $USER_ID = $Login_Information->id;
            $DB->query("UPDATE members SET last_action='$TIMESTAMP' WHERE id='$USER_ID'");
          }else{
            $Login_Error = "YOU ARE CURRENTLY LOGGED IN ALREADY";
          }
        }elseif($Login_Information->account_status == 1){
          if($Login_Information->suspended_timestamp < $TIMESTAMP){
            if(!QUICK_STATUS_CHECK($DB,$Login_Information->id,$TIMESTAMP)){
              $_SESSION["USER_ID"] = $Login_Information->id;
              $USER_ID = $Login_Information->id;
              $DB->query("UPDATE members SET account_status='0' WHERE id='$USER_ID'");
              $DB->query("UPDATE members SET last_action='$TIMESTAMP' WHERE id='$USER_ID'");
            }else{
              $Login_Error = "YOU ARE CURRENTLY LOGGED IN ALREADY";
            }
          }else{
            $Login_Error = "ACCOUNT SUSPENDED FOR 24 HOURS";
          }
        }else{
          $Login_Error = "ACCOUNT BANNED";
        }
      }else{
        $Login_Error = "INCORRECT ACCOUNT INFORMATION";
      }
}
if($USER_ID){
  TEMPLATE(0,0);
      SMOOTH_REDIRECT("Redirecting","index.php");
  TEMPLATE(1,0);
    }else{
      LOGIN_FORCE($USER_ID, $Login_Error);
    }
  break;

 

The code above works 100%, I just want to see if I missed any security things or programmed it crappy.

Link to comment
https://forums.phpfreaks.com/topic/186315-opinions-wanted/
Share on other sites

Looks fine to me. One thing tho, when you create an MD5 hash of a password, you don't need to use real escape strings on it, because you could get some unwanted results. if someone puts a ' in the password, then its md5 hash will be different \'. Besides that, and stylistic differences I might have had, it looks good

 

 

Link to comment
https://forums.phpfreaks.com/topic/186315-opinions-wanted/#findComment-983917
Share on other sites

First off it's none of your concerns wether or not I read the other replies I'm free to post whatever I want just like mods/admins are free to moderate my post/ban my ass. Mods/Admins not you

Second your answer is off-topic and has no value for the OP which is worse?

Third I said the same as oni-kun only simpler

Fourth after a second look I realize I was confused and mysql_real_escape_string does actually nothing to the md5 string, my apologies (to the OP)

Link to comment
https://forums.phpfreaks.com/topic/186315-opinions-wanted/#findComment-983981
Share on other sites

This is very messy!

 

1. I would look up Naming Conventions, you have very hard to read variables, no need to use Login_User, when you are using the _ for a spacer, you could just use login_user; alternatively without the _ spacer you could do loginUser (camelCase).

2. Too many nested if/else statements!

3. Possibly break things into a few more functions

4. Make comments in your code, when you come back to this in a few months I think you will be very confused!

5. Your naming is confusing, perhaps rename your database logic to differentiate between the two (SysCheck rather than LoginCheck, and space out your query to be readable)

      $SysCheck = $DB->query("
		SELECT 	id,username,account_status,suspended_timestamp 
		FROM 	members 
		WHERE 	username='$Login_Username' 
		&& 		password='$Login_Password'");

  /** Login Status counts if a user exists with user/password combo */
      $Login_Status = $SysCheck->num_rows;
      $Login_Information = $SysCheck->fetch_object();

 

6. $DB->real_escape_string is unnecessarily long to type out, why not just name the method $DB->clean or something, I can't imagine typing those underscores so much is that enjoyable!

 

7. An example function

  function ValidUser($str)
  {
/** Returns a Boolean */
return preg_match("/^[a-z0-9]{2,20}$/i", $str) || preg_match("/^[a-z0-9]{2,20}$/i", $str);
  }
  
  
case "Login":

if(!ValidUser($_POST["F_1_Login_Username"]) {
	$Login_Error = "INCORRECT ACCOUNT INFORMATION";
}

Link to comment
https://forums.phpfreaks.com/topic/186315-opinions-wanted/#findComment-983989
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.