October 2018
Beginner
794 pages
19h 23m
English
The following is the wrong approach:
mygetpass(){ numtries=1 <get the password> if (password-is-wrong) { numtries ++ if (numtries >= 3) { <write and log failure message> <abort> } } <password correct, continue>} mylogin(){ mygetpass()}
Now let's take a look at the right approach: the Unix way! Refer to the following code:
mygetpass(){ <get the password> if (password-is-wrong) return false; return true;}mylogin(){ maxtries = 3 while (maxtries--) { if (mygetpass() == true) <move along, call other routines> } // If we're here, we've failed to provide the // correct password <write and log failure message> <abort>}
The job of mygetpass() is to get a password from the user and check whether it's correct; it returns success or failure ...
Read now
Unlock full access