home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2290 / obscure.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  2.8 KB  |  172 lines

  1. /*
  2.  * Copyright 1989, 1990, John F. Haugh II
  3.  * All rights reserved.
  4.  *
  5.  * Use, duplication, and disclosure prohibited without
  6.  * the express written permission of the author.
  7.  */
  8.  
  9. #include <ctype.h>
  10. #ifndef    BSD
  11. #include <string.h>
  12. #include <memory.h>
  13. #else
  14. #include <strings.h>
  15. #define    strchr    index
  16. #define    strrchr    rindex
  17. #endif
  18. #include "config.h"
  19.  
  20. #ifndef    lint
  21. static    char    _sccsid[] = "@(#)obscure.c    2.3    08:58:09    11/5/90";
  22. #endif
  23.  
  24. /*
  25.  * Obscure - see if password is obscure enough.
  26.  *
  27.  *    The programmer is encouraged to add as much complexity to this
  28.  *    routine as desired.  Included are some of my favorite ways to
  29.  *    check passwords.
  30.  */
  31.  
  32. extern    char    pass[];            /* the new password */
  33. extern    char    orig[];            /* the original password */
  34. #ifdef    OBSCURE
  35. char    mono[32];            /* a monocase version of pass */
  36. #endif
  37. int    obscure ()
  38. {
  39. #ifdef    OBSCURE
  40.     int    i;
  41. #endif
  42.     if (orig[0] == '\0')
  43.         return (1);
  44.  
  45.     if (strlen (pass) < PASSLENGTH) { /* too short */
  46.         printf ("Too short.  ");
  47.         return (0);
  48.     }
  49. #ifdef    OBSCURE
  50.     for (i = 0;pass[i];i++)
  51.         mono[i] = tolower (pass[i]);
  52.  
  53.     if (strcmp (pass, orig) == 0)    /* the same */
  54.         return (0);
  55.  
  56.     if (palindrome ())        /* a palindrome */
  57.         return (0);
  58.  
  59.     if (caseshift ())        /* upper/lower case changes only */
  60.         return (0);
  61.  
  62.     if (similiar ())        /* jumbled version of original */
  63.         return (0);
  64.  
  65.     if (simple ())            /* keyspace size */
  66.         return (0);
  67. #endif
  68.     return (1);
  69. }
  70.  
  71. #ifdef    OBSCURE
  72.  
  73. /*
  74.  * can't be a palindrome - like `R A D A R' or `M A D A M'
  75.  */
  76.  
  77. int    palindrome ()
  78. {
  79.     int    i, j;
  80.  
  81.     i = strlen (pass);
  82.  
  83.     for (j = 0;j < i;j++)
  84.         if (pass[i - j - 1] != pass[j])
  85.             return (0);
  86.  
  87.     printf ("No palindromes.  ");
  88.     return (1);
  89. }
  90.  
  91. /*
  92.  * may not be a shifted version of original
  93.  */
  94.  
  95. int    caseshift ()
  96. {
  97.     int    i;
  98.  
  99.     for (i = 0;pass[i] && orig[i];i++) {
  100.         if (tolower (pass[i]) == tolower (orig[i]))
  101.             continue;
  102.         else
  103.             return (0);
  104.     }
  105.     printf ("May not be case-shifted.  ");
  106.     return (1);
  107. }
  108.  
  109. /*
  110.  * more than half of the characters are different ones.
  111.  */
  112.  
  113. int    similiar ()
  114. {
  115.     int    i, j;
  116.     char    *strchr ();
  117.  
  118.     for (i = j = 0;pass[i] && orig[i];i++)
  119.         if (strchr (mono, tolower (orig[i])))
  120.             j++;
  121.  
  122.     if (i >= j * 2)
  123.         return (0);
  124.  
  125.     printf ("Too similiar.  ");
  126.     return (1);
  127. }
  128.  
  129. /*
  130.  * a nice mix of characters.
  131.  */
  132.  
  133. int    simple ()
  134. {
  135.     int    digits = 0;
  136.     int    uppers = 0;
  137.     int    lowers = 0;
  138.     int    others = 0;
  139.     int    size;
  140.     int    i;
  141.     double    complexity;
  142.  
  143.     for (i = 0;pass[i];i++) {
  144.         if (isdigit (pass[i]))
  145.             digits++;
  146.         else if (isupper (pass[i]))
  147.             uppers++;
  148.         else if (islower (pass[i]))
  149.             lowers++;
  150.         else
  151.             others++;
  152.     }
  153.  
  154.     /*
  155.      * The scam is this - a password of only one character type
  156.      * must be 8 letters long.  Two types, 7, and so on.
  157.      */
  158.  
  159.     size = 9;
  160.     if (digits) size--;
  161.     if (uppers) size--;
  162.     if (lowers) size--;
  163.     if (others) size--;
  164.  
  165.     if (size <= i)
  166.         return 0;
  167.  
  168.     printf ("Too Simple.  ");
  169.     return 1;
  170. }
  171. #endif
  172.