home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume6 / shadow-2.pt2 / obscure.c < prev    next >
C/C++ Source or Header  |  1989-02-03  |  2KB  |  104 lines

  1. #include <ctype.h>
  2. #include "config.h"
  3.  
  4. /*
  5.  * Obscure - see if password is obscure enough.
  6.  *
  7.  *    The programmer is encouraged to add as much complexity to this
  8.  *    routine as desired.  Included are some of my favorite ways to
  9.  *    check passwords.
  10.  */
  11.  
  12. extern    char    pass[];            /* the new password */
  13. extern    char    orig[];            /* the original password */
  14. char    mono[32];            /* a monocase version of pass */
  15.  
  16. int    obscure ()
  17. {
  18.     int    i;
  19.  
  20.     if (orig[0] == '\0')
  21.         return (1);
  22.  
  23.     if (strlen (pass) < 6) {    /* too short */
  24.         printf ("Too short.  ");
  25.         return (0);
  26.     }
  27. #ifdef    OBSCURE
  28.     for (i = 0;pass[i];i++)
  29.         mono[i] = tolower (pass[i]);
  30.  
  31.     if (strcmp (pass, orig) == 0)    /* the same */
  32.         return (0);
  33.  
  34.     if (palindrome ())        /* a palindrome */
  35.         return (0);
  36.  
  37.     if (caseshift ())        /* upper/lower case changes only */
  38.         return (0);
  39.  
  40.     if (similiar ())        /* jumbled version of original */
  41.         return (0);
  42. #endif
  43.     return (1);
  44. }
  45.  
  46. #ifdef    OBSCURE
  47.  
  48. /*
  49.  * can't be a palindrome - like `R A D A R' or `M A D A M'
  50.  */
  51.  
  52. int    palindrome ()
  53. {
  54.     int    i, j;
  55.  
  56.     i = strlen (pass);
  57.  
  58.     for (j = 0;j < i;j++)
  59.         if (pass[i - j - 1] != pass[j])
  60.             return (0);
  61.  
  62.     printf ("No palindromes.  ");
  63.     return (1);
  64. }
  65.  
  66. /*
  67.  * may not be a shifted version of original
  68.  */
  69.  
  70. int    caseshift ()
  71. {
  72.     int    i;
  73.  
  74.     for (i = 0;pass[i] && orig[i];i++) {
  75.         if (tolower (pass[i]) == tolower (orig[i]))
  76.             continue;
  77.         else
  78.             return (0);
  79.     }
  80.     printf ("May not be case-shifted.  ");
  81.     return (1);
  82. }
  83.  
  84. /*
  85.  * more than half of the characters are different ones.
  86.  */
  87.  
  88. int    similiar ()
  89. {
  90.     int    i, j;
  91.     char    *strchr ();
  92.  
  93.     for (i = j = 0;pass[i] && orig[i];i++)
  94.         if (strchr (mono, tolower (orig[i])))
  95.             j++;
  96.  
  97.     if (i - j > 2)
  98.         return (0);
  99.  
  100.     printf ("Too similiar.  ");
  101.     return (1);
  102. }
  103. #endif
  104.