home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1989, 1990, John F. Haugh II
- * All rights reserved.
- *
- * Use, duplication, and disclosure prohibited without
- * the express written permission of the author.
- */
-
- #include <ctype.h>
- #ifndef BSD
- #include <string.h>
- #include <memory.h>
- #else
- #include <strings.h>
- #define strchr index
- #define strrchr rindex
- #endif
- #include "config.h"
-
- #ifndef lint
- static char _sccsid[] = "@(#)obscure.c 2.3 08:58:09 11/5/90";
- #endif
-
- /*
- * Obscure - see if password is obscure enough.
- *
- * The programmer is encouraged to add as much complexity to this
- * routine as desired. Included are some of my favorite ways to
- * check passwords.
- */
-
- extern char pass[]; /* the new password */
- extern char orig[]; /* the original password */
- #ifdef OBSCURE
- char mono[32]; /* a monocase version of pass */
- #endif
- int obscure ()
- {
- #ifdef OBSCURE
- int i;
- #endif
- if (orig[0] == '\0')
- return (1);
-
- if (strlen (pass) < PASSLENGTH) { /* too short */
- printf ("Too short. ");
- return (0);
- }
- #ifdef OBSCURE
- for (i = 0;pass[i];i++)
- mono[i] = tolower (pass[i]);
-
- if (strcmp (pass, orig) == 0) /* the same */
- return (0);
-
- if (palindrome ()) /* a palindrome */
- return (0);
-
- if (caseshift ()) /* upper/lower case changes only */
- return (0);
-
- if (similiar ()) /* jumbled version of original */
- return (0);
-
- if (simple ()) /* keyspace size */
- return (0);
- #endif
- return (1);
- }
-
- #ifdef OBSCURE
-
- /*
- * can't be a palindrome - like `R A D A R' or `M A D A M'
- */
-
- int palindrome ()
- {
- int i, j;
-
- i = strlen (pass);
-
- for (j = 0;j < i;j++)
- if (pass[i - j - 1] != pass[j])
- return (0);
-
- printf ("No palindromes. ");
- return (1);
- }
-
- /*
- * may not be a shifted version of original
- */
-
- int caseshift ()
- {
- int i;
-
- for (i = 0;pass[i] && orig[i];i++) {
- if (tolower (pass[i]) == tolower (orig[i]))
- continue;
- else
- return (0);
- }
- printf ("May not be case-shifted. ");
- return (1);
- }
-
- /*
- * more than half of the characters are different ones.
- */
-
- int similiar ()
- {
- int i, j;
- char *strchr ();
-
- for (i = j = 0;pass[i] && orig[i];i++)
- if (strchr (mono, tolower (orig[i])))
- j++;
-
- if (i >= j * 2)
- return (0);
-
- printf ("Too similiar. ");
- return (1);
- }
-
- /*
- * a nice mix of characters.
- */
-
- int simple ()
- {
- int digits = 0;
- int uppers = 0;
- int lowers = 0;
- int others = 0;
- int size;
- int i;
- double complexity;
-
- for (i = 0;pass[i];i++) {
- if (isdigit (pass[i]))
- digits++;
- else if (isupper (pass[i]))
- uppers++;
- else if (islower (pass[i]))
- lowers++;
- else
- others++;
- }
-
- /*
- * The scam is this - a password of only one character type
- * must be 8 letters long. Two types, 7, and so on.
- */
-
- size = 9;
- if (digits) size--;
- if (uppers) size--;
- if (lowers) size--;
- if (others) size--;
-
- if (size <= i)
- return 0;
-
- printf ("Too Simple. ");
- return 1;
- }
- #endif
-