Jump to content

Using uppercase PW check.


IamSuchANoob

Recommended Posts

Problem - application produces MD5 PWs which are uppercase, code checks lowercase.

Question- How to use uppercase check?

 

function checkPwd($x,$y)
{
    //Checks if strings are empty

    if(empty($x) || empty($y) )
    {
        //Strings were empty
        return false;
    }
    else if(strlen($x) < 4 || strlen($y) < 4)
    {
        //String length too short
        return false;
    }
    else if(strcmp($x,$y) != 0)
    {
        //Strings do not match
        return false;
    }
    else
    {
        //Password Determined valid
        return true;

    }
}

 

Question 2: Do I have to change it anywhere else, like PW generation?

function GenPwd($length = 7)
{
  $password = "";
  $possible = "0123456789bcdfghjkmnpqrstvwxyz"; //no vowels
  
  $i = 0; 
    
  while ($i < $length) { 

    
    $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
       
    
    if (!strstr($password, $char)) { 
      $password .= $char;
      $i++;
    }

  }

  return $password;

}

function GenKey($length = 7)
{
  $password = "";
  $possible = "0123456789abcdefghijkmnopqrstuvwxyz"; 
  
  $i = 0; 
    
  while ($i < $length) { 

    
    $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
       
    
    if (!strstr($password, $char)) { 
      $password .= $char;
      $i++;
    }

  }

  return $password;

}

 

Thank you for reading :)

Link to comment
Share on other sites

i dont really see anywhere in that code that passwords have to be uppercase. In your first function, everything depends on your two input arguments, and regardless of if they are uppercase, or lowercase, they have to be  the same for the function to return true.

 

if you need to convert something to uppercase though, use the toupper function. Similarly, to convert to lowercase, there is a tolower function

Link to comment
Share on other sites

i dont really see anywhere in that code that passwords have to be uppercase. In your first function, everything depends on your two input arguments, and regardless of if they are uppercase, or lowercase, they have to be  the same for the function to return true.

 

if you need to convert something to uppercase though, use the toupper function. Similarly, to convert to lowercase, there is a tolower function

awkward. the code simply doesnt recognize the uppercase PWs. I checked in DB, if I convert the PW lowercase, everything is ok.

Link to comment
Share on other sites

one thing to note though is that case-sensitive passwords are stronger, so ideally you should be matching up how you generate/store them, and making the check case-sensitive. 

 

For example, treating all of these as the same thing makes for less work in trying to crack a password:

 

aaa

aaA

aAa

aAA

Aaa

AaA

AAa

AAA

 

 

Link to comment
Share on other sites

Okay, I didnt explain myself good enough.

The password encryption from application is uppercase. I suppose the problem is within application, not the code.

 

Example.

 

md5 Encryption for 'hi' is:

 

49f68a5c8493ec2c0bf489821c21fc3b

 

and from our application it comes as:

 

49F68A5C849EC2C0BF489821C21FC3B

 

So there comes the problem, php does not think its the same PW.

 

P.S Sorry for saying it was PW not the encryption itself :P

Link to comment
Share on other sites

md5 doesn't capitalize strings and I can't see anywhere in your code that takes a user inputted password, only your password generator, which granted, only contains lower case characters. However md5 is case sensitive so will hash A differently to a, therefor comparing two md5 hashed strings will return true if they match case. Are you storing your hash in a database field that is integer type or varchar less than  32 bit?

 

 

Otherwise, I must be missing something obvious in your question because everyone else seems to know what you're talking about...

 

 

 

 

Link to comment
Share on other sites

Okay, I didnt explain myself good enough.

The password encryption from application is uppercase. I suppose the problem is within application, not the code.

 

Example.

 

md5 Encryption for 'hi' is:

 

49f68a5c8493ec2c0bf489821c21fc3b

 

and from our application it comes as:

 

49F68A5C849EC2C0BF489821C21FC3B

 

So there comes the problem, php does not think its the same PW.

 

P.S Sorry for saying it was PW not the encryption itself :P

 

 

Sorry my bad, have you checked if your code is calling strtoupper on the variable between md5 hashing it and storing it?

Link to comment
Share on other sites

How could I implement strcasecmp?

 

function checkPwd($x,$y)
{
    //Checks if strings are empty

    if(empty($x) || empty($y) )
    {
        //Strings were empty
        return false;
    }
    else if(strlen($x) < 4 || strlen($y) < 4)
    {
        //String length too short
        return false;
    }
    else if(strcasecmp($x,$y) != 0)
    {
        //Strings do not match
        return false;
    }
    else
    {
        //Password Determined valid
        return true;

    }
}

This does not work, if the MD5 is uppercase, it says incorrect PW.

Link to comment
Share on other sites

well it has since been determined that you're performing a check on the md5 hash, and md5 hashes are case-sensitive.  So you will need to do a strtolower on your md5 hash since it is uppercased in your db for some reason, but ideally, you should be changing your script that uppercases it to begin with, before it goes into the db.

Link to comment
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.