Better function? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Better function? (
/showthread.php?tid=598784)
Better function? -
Kimble - 16.01.2016
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
Re: Better function? -
PrO.GameR - 16.01.2016
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'
Re: Better function? -
Vince - 16.01.2016
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.
Re: Better function? -
PrO.GameR - 17.01.2016
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.