-tryagain:
- (void) strcpy(pwbuf, getpass("New password:"));
- pwlen = strlen(pwbuf);
- if (pwlen == 0) {
- printf("Password unchanged.\n");
- exit(1);
- }
- /*
- * Insure password is of reasonable length and
- * composition. If we really wanted to make things
- * sticky, we could check the dictionary for common
- * words, but then things would really be slow.
- */
- ok = 0;
- flags = 0;
- p = pwbuf;
- while (c = *p++) {
- if (c >= 'a' && c <= 'z')
- flags |= 2;
- else if (c >= 'A' && c <= 'Z')
- flags |= 4;
- else if (c >= '0' && c <= '9')
- flags |= 1;
- else
- flags |= 8;
- }
- if (flags >= 7 && pwlen >= 4)
- ok = 1;
- if ((flags == 2 || flags == 4) && pwlen >= 6)
- ok = 1;
- if ((flags == 3 || flags == 5 || flags == 6) && pwlen >= 5)
- ok = 1;
- if (!ok && insist < 2) {
- printf("Please use %s.\n", flags == 1 ?
- "at least one non-numeric character" :
- "a longer password");
- insist++;
- goto tryagain;
+ for(;;) {
+ (void)strcpy(pwbuf, getpass("New password:"));
+ if (!*pwbuf) {
+ puts("Password unchanged.");
+ exit(1);
+ }
+ if (strcmp(pwbuf, pwcopy)) {
+ insist = 1;
+ (void)strcpy(pwcopy, pwbuf);
+ }
+ else if (++insist == 4)
+ break;
+ if (checkpass(pwbuf))
+ break;