home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3345 / obscure.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-17  |  3.0 KB  |  175 lines

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