Better function?
#1

So i have this two functions in my gamemode:

Код:
stock IsValidPassword( const password[ ] )
{
    for( new i = 0; password[ i ] != EOS; ++i )
	{
        switch( password[ i ] )
		{
            case '0'..'9', 'A'..'Z', 'a'..'z': continue;
            default: return 0;
        }
    }
    return 1;
}
and

Код:
stock IsPassOK(pass[])
{
	new length = strlen(pass);
	
	// If the length is okay.
	if(length >= 3 && length <= 15)
	{
		// Only letters and numbers.
		for(new i = 0; i < length; i++)
		{
		    // As soon as it finds something other than letters / numbers it breaks the loop and returns false.
		    if((pass[i] < 'a' || pass[i] > 'z') && (pass[i] < 'A' || pass[i] > 'Z') && (pass[i] < '0' || pass[i] > '9')) { return 0; }
		}
		
		return 1;
	}
	
	return 0;
}
Both do the same thing (check that the password is a-z A-Z 0-9) but which one is better? I like the second one because is commented but the first one is neater. In terms of speed which one is better? Thank you
Reply
#2

First one because it uses switch, so is faster, second one however got one more extra check so people wouldn't save a password like 'a'
Reply
#3

This might be besides the point, but limiting a password in any way, be it max length or allowed characters insinuates that you are storing it in plain text, or that you're otherwise using a very insecure storage method. Which is, of course, bad. A hashing method doesn't care about its input and it will always output a fixed length string.

If this is to be used for anything in-game (e.g. a password protected door or something) then I've said nothing.
Reply
#4

Quote:
Originally Posted by Vince
Посмотреть сообщение
This might be besides the point, but limiting a password in any way, be it max length or allowed characters insinuates that you are storing it in plain text, or that you're otherwise using a very insecure storage method. Which is, of course, bad. A hashing method doesn't care about its input and it will always output a fixed length string.

If this is to be used for anything in-game (e.g. a password protected door or something) then I've said nothing.
Loled at second part xD
About first part, I really believe there should be a min char limit, and does hashing space work too ? For some reason I always disallow space in my password strings.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)