java - Generating different passwords according to a string - Activation Key -


i'm trying make program activated password on java. while user registering, "teacher pass" given authorized personal asked , if it's correct, program allow user use itself.

students can use program can't reach of content.

private static string encrypt() {        string s = "cornflakes";     string pass = "";     random rnd = new random();     int = rnd.nextint(s.length());     for(int j = 0; j < 7; j++)     {         pass += ""+ + s.charat(i);         = rnd.nextint(s.length());     }     return pass; }   private static boolean decrypt (string s) {        if(s.length() != 14)         return false;     string teacherpass = "cornflakes";     string[] tokens = s.split("a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|q|p|r|s|t|u|v|w|x|y|z");     int loc;     for(int = 0; i< 7; i++)     {         loc = integer.parseint(tokens[i]);         if(s.charat(2*i+1) != teacherpass.charat(loc))             return false;     }       return true; } 

definetly there better solution it, is? way, use mysql keeping user info.

you should hashing storing passwords , hash again on login , compare hashes.

for instance: http://en.wikipedia.org/wiki/sha-2

hashing (when used , implemented) has nice property password storage , validation: procedure can't reversed. if access user credentials table, not learn users password. checking entered password against stored hash happens hashing new input aswell , comparing hashes.

also should never write things if not security expert because invariably make small mistake makes whole system insecure. use suitable libraries.

you should salts hashes, start simple hashes , move on once understand basics.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -