16.01.2016, 19:02
So i have this two functions in my gamemode:
and
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
Код:
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; }
Код:
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; }