home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / unix_c / languags / c / passwdet.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-21  |  12.8 KB  |  260 lines

  1. 25-Nov-85 20:37:22-MST,13340;000000000001
  2. Return-Path: <unix-sources-request@BRL.ARPA>
  3. Received: from BRL-TGR.ARPA by SIMTEL20.ARPA with TCP; Mon 25 Nov 85 20:36:54-MST
  4. Received: from usenet by TGR.BRL.ARPA id a029511; 25 Nov 85 21:54 EST
  5. From: jbn@wdl1.uucp
  6. Newsgroups: net.sources
  7. Subject: Obvious password detector (reposted)
  8. Message-ID: <879@wdl1.UUCP>
  9. Date: 23 Nov 85 06:25:37 GMT
  10. Sender: notes@wdl1.uucp
  11. Nf-ID: #N:wdl1:64200002:000:12602
  12. Nf-From: wdl1!jbn    Nov 22 18:41:00 1985
  13. To:       unix-sources@BRL-TGR.ARPA
  14.  
  15. /*
  16.     Obvious password detection subroutine.
  17.  
  18.     Call:
  19.  
  20.         char word[];
  21.         char *obvious(word);
  22.  
  23.     Returns 0 if password is acceptable.
  24.     Returns a pointer to a static message if the password is unacceptable.
  25.  
  26.     The algorithm used requires that the length of the password be
  27.     within configurable length limits, and that the password not
  28.     have triplet statistics similar to those associated with words
  29.     in the English language.  This is an inversion of a technique
  30.     used to find spelling errors without a full dictionary.  No
  31.     word in the UNIX spelling dictionary will pass this algorithm.
  32.  
  33.     Users should be advised to pick a password composed of random
  34.     letters and numbers.  Eight randomly chosen letters will
  35.     pass the algorithm over 95% of the time.  A word prefaced
  36.     by a digit will not pass the algorithm, although a word
  37.     with a digit in the middle usually will.  Two words run
  38.     together will often pass.
  39.  
  40.     In the interest of greater network security, this algorithm
  41.     is offered to the ARPANET community as a proposed standard technique
  42.     for eliminating obvious passwords.
  43.  
  44.                 John Nagle
  45.                 Ford Aerospace and Communications Corporation
  46.                 Western Development Laboratories
  47.                 3939 Fabian Way
  48.                 Palo Alto, CA  94303
  49.                 
  50.                 1/16/84
  51. */
  52. /*
  53.         Table of triple usage in text
  54.  
  55.         24511 words were used to make this table.
  56.         The words came from the files:
  57.             /usr/dict/words
  58.             obvpats.lp
  59.  
  60.         The table is 30 percent populated.
  61. */
  62. long obvtab[27][27] =
  63. {
  64.     {    0X00100001, 0X00040000, 0X00040000, 0X00009000, 0X00808020, 0X00140000, 
  65.     0X00000000, 0X00080000, 0X00000002, 0X00000000, 0X00000000, 0X00000000, 
  66.     0X00001020, 0X00000000, 0X00000010, 0X00000020, 0X00000000, 0X00000000, 
  67.     0X00000030, 0X00300100, 0X00000100, 0X00000000, 0X00000020, 0X00000000, 
  68.     0X00000000, 0X00000000, 0X00000000 },
  69.     {    0X00090000, 0X000c708a, 0X022cd73e, 0X023ffbbe, 0X02fffffe, 0X002cd0da, 
  70.     0X023cdae2, 0X02adf3b6, 0X0024f222, 0X00dd7efa, 0X00008022, 0X02b5937a, 
  71.     0X06fdfbfe, 0X02bdf37e, 0X07ffdfff, 0X003c3248, 0X023dfb76, 0X00200000, 
  72.     0X07fffffe, 0X02bbfbbe, 0X06bcfb6f, 0X055f7dfc, 0X02609232, 0X021cfbf6, 
  73.     0X02999222, 0X00bdf3ff, 0X06308232 },
  74.     {    0X00080000, 0X07fdfbfc, 0X022c9226, 0X00008012, 0X00248222, 0X07dffbfe, 
  75.     0X00200000, 0X00000000, 0X00208020, 0X047ffdfe, 0X00000020, 0X00000000, 
  76.     0X02208222, 0X00800220, 0X0000a022, 0X03fdfffe, 0X00048000, 0X00000000, 
  77.     0X02208222, 0X00308228, 0X00049062, 0X071efefc, 0X00000220, 0X00000020, 
  78.     0X00000000, 0X049d11a2, 0X00000000 },
  79.     {    0X00080080, 0X02fffffe, 0X000c0020, 0X0024932a, 0X0000802a, 0X06bdf3fe, 
  80.     0X00000002, 0X00248220, 0X02bdf3fe, 0X007df0fe, 0X00000000, 0X02bdfffe, 
  81.     0X02208222, 0X00200222, 0X00008222, 0X07fffffe, 0X00000102, 0X00200000, 
  82.     0X02308222, 0X00188200, 0X02aca262, 0X003df27e, 0X00000004, 0X00000000, 
  83.     0X00000000, 0X001dd08e, 0X00000022 },
  84.     {    0X00088022, 0X06fd7bfc, 0X02249222, 0X00209102, 0X02249332, 0X07fff7fe, 
  85.     0X00249282, 0X02a43a22, 0X00008222, 0X05fdf3fe, 0X00208022, 0X00000220, 
  86.     0X02208222, 0X00208222, 0X00008223, 0X07fdf3fe, 0X00049322, 0X00200000, 
  87.     0X02208222, 0X0091bb2a, 0X00008302, 0X043dfafe, 0X00008222, 0X02048222, 
  88.     0X00000000, 0X00987aef, 0X00200000 },
  89.     {    0X004c1030, 0X04ff79dc, 0X023c9226, 0X023c9b3a, 0X02bdf3fe, 0X04ddfbfe, 
  90.     0X023c92fa, 0X0224f3e6, 0X0224a222, 0X045d7afa, 0X00208022, 0X0218ca36, 
  91.     0X02fdfbfe, 0X02a9f22e, 0X06ffffff, 0X05fd73d8, 0X02bdb32e, 0X00200000, 
  92.     0X07fffffe, 0X02fbfbbe, 0X06bdfb6e, 0X005d78bc, 0X066c8222, 0X029df37e, 
  93.     0X0333832a, 0X008df97f, 0X06648222 },
  94.     {    0X00080000, 0X07bc7bfe, 0X00000222, 0X0000000a, 0X00008002, 0X02fc7abe, 
  95.     0X022cb366, 0X00000102, 0X00000022, 0X055c70fe, 0X00008000, 0X00000002, 
  96.     0X02208222, 0X0000000a, 0X00000200, 0X03edf2be, 0X00000008, 0X00000000, 
  97.     0X02208222, 0X00118922, 0X028ca32e, 0X041c74b8, 0X00000000, 0X00000002, 
  98.     0X00000000, 0X00000000, 0X00000000 },
  99.     {    0X00080000, 0X06fdf3fc, 0X00008222, 0X00000000, 0X00008022, 0X02fdf3fe, 
  100.     0X00240220, 0X020d93a2, 0X02bddffe, 0X047df0fe, 0X00000002, 0X00008200, 
  101.     0X02208222, 0X02300222, 0X00318226, 0X02fdf3fe, 0X00009220, 0X00000000, 
  102.     0X02208222, 0X00919b06, 0X00048302, 0X061cf2ee, 0X00000000, 0X02048022, 
  103.     0X00000000, 0X00056002, 0X00000002 },
  104.     {    0X00080000, 0X06fdfbfe, 0X02249222, 0X00048102, 0X00048202, 0X07fff2ff, 
  105.     0X00208202, 0X00008022, 0X00008122, 0X047dfcfe, 0X00000800, 0X00008220, 
  106.     0X02248222, 0X0008a222, 0X0028c222, 0X06fdfeff, 0X00209202, 0X00200000, 
  107.     0X02249232, 0X00108302, 0X02bdf3fa, 0X071d71fe, 0X00000200, 0X00008322, 
  108.     0X00000000, 0X011d32be, 0X00000000 },
  109.     {    0X00483010, 0X05dd7bbc, 0X022cf226, 0X023cdb2a, 0X02bdf6b6, 0X04fd79fc, 
  110.     0X0234d262, 0X063df3a2, 0X00000222, 0X00000202, 0X00208002, 0X02208a22, 
  111.     0X02fdbbfe, 0X022df36e, 0X07ffffff, 0X05fd70be, 0X02bdb766, 0X00200000, 
  112.     0X02fdfafe, 0X02ffffff, 0X06bdfb6f, 0X000c7008, 0X02248222, 0X00008202, 
  113.     0X023082e2, 0X00000002, 0X04608022 },
  114.     {    0X00080000, 0X07ed7bbc, 0X00000000, 0X00000000, 0X00000000, 0X009cd57a, 
  115.     0X00000000, 0X00000000, 0X00000000, 0X005070c4, 0X00000400, 0X00001000, 
  116.     0X00000000, 0X00000000, 0X00000000, 0X02fc5bae, 0X00000000, 0X00000000, 
  117.     0X00000000, 0X00000000, 0X00000000, 0X015d7e96, 0X00000000, 0X00000000, 
  118.     0X00000000, 0X00000000, 0X00000000 },
  119.     {    0X00080000, 0X07fdfff4, 0X00248222, 0X00040302, 0X00048022, 0X02fdf3f6, 
  120.     0X00208222, 0X00048000, 0X0014a022, 0X00ddf8fe, 0X00000002, 0X0000ca22, 
  121.     0X0220a222, 0X00000022, 0X00208222, 0X01fdfb7a, 0X00009202, 0X00000000, 
  122.     0X02208222, 0X02b1abae, 0X00048302, 0X029d7110, 0X00000000, 0X00008322, 
  123.     0X00000000, 0X00ac9522, 0X00000000 },
  124.     {    0X00088000, 0X07fffbfe, 0X02249222, 0X0234b322, 0X02bdf36e, 0X07fdfffe, 
  125.     0X00bc93e6, 0X00048222, 0X00008222, 0X05fffdfe, 0X00008000, 0X0288d322, 
  126.     0X02bdb7fe, 0X0228e332, 0X00208020, 0X07fffffe, 0X021ca362, 0X00000000, 
  127.     0X02208022, 0X0299ab26, 0X06eca326, 0X055dfefe, 0X00008222, 0X02008322, 
  128.     0X00000000, 0X00bdfbfe, 0X00000022 },
  129.     {    0X00080000, 0X07fdffbc, 0X002dd236, 0X0021fbfe, 0X00008020, 0X07ddfbfe, 
  130.     0X00209220, 0X00000000, 0X00208020, 0X053efcfa, 0X00000000, 0X00000000, 
  131.     0X00008222, 0X0220a222, 0X02208222, 0X07fdfbfe, 0X023c9be6, 0X00200000, 
  132.     0X00088002, 0X0239a37c, 0X00048120, 0X041dfaf8, 0X00000020, 0X00008222, 
  133.     0X00000000, 0X001cd0a8, 0X00000000 },
  134.     {    0X00180000, 0X06fdfbfe, 0X002c922a, 0X02349b22, 0X02bffffe, 0X07fff3ff, 
  135.     0X00249222, 0X02bdbb76, 0X02208222, 0X057ffbfe, 0X00208022, 0X021d33ea, 
  136.     0X02008222, 0X00008222, 0X0228c222, 0X07fdf2fe, 0X00209220, 0X00200000, 
  137.     0X0220822a, 0X02fdfbfe, 0X06adf3ee, 0X043dfafe, 0X02208222, 0X00048322, 
  138.     0X00100200, 0X01ffb11e, 0X02808222 },
  139.     {    0X0008113c, 0X017f79da, 0X02fcd77e, 0X02349b2a, 0X02adfbfe, 0X037ef35c, 
  140.     0X0234b262, 0X02bcf7f6, 0X0204f222, 0X011c58fe, 0X00008222, 0X02a99b2e, 
  141.     0X06fdfbfe, 0X02aff36e, 0X07ffffff, 0X045df9dc, 0X02bffbae, 0X00200000, 
  142.     0X06fffbfe, 0X02fbbbae, 0X02bdf3ee, 0X055f73ff, 0X02008a22, 0X06bdfb7e, 
  143.     0X02d043ea, 0X001dd37e, 0X06008222 },
  144.     {    0X00080000, 0X07fffabc, 0X002c9022, 0X00008100, 0X00040002, 0X07fdfefe, 
  145.     0X00241220, 0X00040002, 0X023cd232, 0X057ff8fa, 0X00000002, 0X00000220, 
  146.     0X02208222, 0X00208022, 0X00008020, 0X03fdfafa, 0X022db322, 0X00040000, 
  147.     0X02208222, 0X02b0bb2a, 0X0224832a, 0X041d7afe, 0X00000008, 0X00048202, 
  148.     0X00000000, 0X00949b86, 0X00000000 },
  149.     {    0X00080000, 0X00100000, 0X00000000, 0X00000000, 0X00000000, 0X00000010, 
  150.     0X00000000, 0X00000000, 0X00000000, 0X00000000, 0X00000000, 0X00000000, 
  151.     0X00000000, 0X00000000, 0X00000000, 0X00000000, 0X00000000, 0X00020000, 
  152.     0X00080000, 0X00000000, 0X00000000, 0X02008222, 0X00000000, 0X00000020, 
  153.     0X00000000, 0X00000000, 0X00000000 },
  154.     {    0X00080010, 0X07fffffc, 0X022c9222, 0X023c9b2a, 0X02bdd366, 0X07ffffff, 
  155.     0X00249222, 0X022cb322, 0X02208222, 0X07fbfdfe, 0X00208020, 0X029df336, 
  156.     0X02b98236, 0X0239936e, 0X02b9ab66, 0X07fffffe, 0X023cb322, 0X00200000, 
  157.     0X02248322, 0X02f3fb7e, 0X06bcf3ee, 0X01ddf2fe, 0X02208222, 0X00008222, 
  158.     0X00000020, 0X0099f0be, 0X00008222 },
  159.     {    0X00081000, 0X03fdfffe, 0X02248222, 0X0224b323, 0X00248242, 0X07fffbfe, 
  160.     0X02208222, 0X002c8220, 0X02f5fa6e, 0X057ff8fe, 0X00200000, 0X0224a222, 
  161.     0X02208222, 0X02208222, 0X02208223, 0X06f5f7fe, 0X022c9326, 0X00200000, 
  162.     0X00288222, 0X02bdf36e, 0X02edf7ff, 0X041df2fe, 0X00010220, 0X00248222, 
  163.     0X00000000, 0X001d78bc, 0X00000000 },
  164.     {    0X001c1010, 0X03fdfbfc, 0X00248222, 0X02249102, 0X00048000, 0X03fdfbfe, 
  165.     0X00249222, 0X00248022, 0X02bffbfe, 0X047ff8fe, 0X00000000, 0X02000222, 
  166.     0X02208222, 0X00208222, 0X00308223, 0X07fdfafe, 0X00049222, 0X00000000, 
  167.     0X02a08222, 0X02f1ab7e, 0X027c9be2, 0X031df2fe, 0X00000202, 0X01208322, 
  168.     0X00000000, 0X01ad328e, 0X000db2a2 },
  169.     {    0X004c1010, 0X02dd7bdc, 0X027db736, 0X023c9b2a, 0X06ac92b6, 0X063df5f6, 
  170.     0X0030b042, 0X002cf3a2, 0X00004002, 0X057dd0be, 0X00208202, 0X00048a30, 
  171.     0X06fdfafe, 0X007bf36e, 0X02bdfbfe, 0X023d5210, 0X02bdbbfe, 0X00200000, 
  172.     0X06fffbfe, 0X023bdbbe, 0X06bcf3be, 0X00202000, 0X00840220, 0X00000002, 
  173.     0X00309220, 0X00601022, 0X04208022 },
  174.     {    0X00080000, 0X003d7fbc, 0X00004000, 0X00000000, 0X00000002, 0X039dfbfe, 
  175.     0X00000000, 0X00000000, 0X00000000, 0X057cdafe, 0X00000000, 0X00000100, 
  176.     0X00008002, 0X00000000, 0X00000000, 0X02bcfa88, 0X00000000, 0X00000000, 
  177.     0X00008020, 0X00000800, 0X00000000, 0X000c1000, 0X02400220, 0X01000000, 
  178.     0X00000000, 0X00800200, 0X00008000 },
  179.     {    0X00080000, 0X077d7bde, 0X00248222, 0X00208102, 0X02248220, 0X025d53bf, 
  180.     0X00209202, 0X00000200, 0X02208222, 0X055d70f8, 0X00000000, 0X02804200, 
  181.     0X02180222, 0X00000222, 0X02bd03fc, 0X00fdf864, 0X00209222, 0X00000000, 
  182.     0X02008222, 0X02bdbb2c, 0X00208322, 0X00057100, 0X00000000, 0X00808002, 
  183.     0X02000000, 0X0000f022, 0X02000000 },
  184.     {    0X00080000, 0X005870d8, 0X00000000, 0X00649322, 0X00000000, 0X021c7298, 
  185.     0X00008000, 0X00201000, 0X00208202, 0X0058f0fe, 0X00000000, 0X00000000, 
  186.     0X00000020, 0X00000000, 0X00000002, 0X001d6090, 0X00249222, 0X00200000, 
  187.     0X00000000, 0X00000020, 0X02248326, 0X00051016, 0X00000200, 0X00008020, 
  188.     0X01008000, 0X04041080, 0X00000000 },
  189.     {    0X004c1010, 0X0097f998, 0X00248232, 0X00009322, 0X0004c226, 0X00ddf0f6, 
  190.     0X00201222, 0X0224f230, 0X02048020, 0X00094030, 0X00000002, 0X00004420, 
  191.     0X00699a22, 0X0221e22e, 0X0310c3ba, 0X04fd78d8, 0X023dd322, 0X00200000, 
  192.     0X0234c272, 0X0039b32e, 0X02108322, 0X00095b88, 0X00000022, 0X0004832a, 
  193.     0X00000200, 0X02000000, 0X00000002 },
  194.     {    0X00080000, 0X00557b8e, 0X00000000, 0X00000000, 0X00000002, 0X00bc5a3e, 
  195.     0X00000000, 0X00000020, 0X00000000, 0X003df0ae, 0X00000000, 0X00000000, 
  196.     0X02008020, 0X00000002, 0X00000000, 0X0065e2b2, 0X00000002, 0X00000000, 
  197.     0X00008002, 0X00000008, 0X00000020, 0X00040820, 0X00008020, 0X00008020, 
  198.     0X00000008, 0X00002084, 0X06809222 } };
  199. /*
  200.     Configuration parameters
  201. */
  202. #define MINLENGTH 5            /* minimum password length */
  203. #define MAXLENGTH 8            /* maximum password length */
  204. #define MINNOFIND 2            /* minimum unusual triples */
  205. short unusual;                /* count of unusual triples */
  206. /*
  207.     obvious  --  test word for obviousness as password
  208.  
  209.     Words are rejected for being too short, too long, 
  210.     or looking too much like English words.
  211. */
  212. char *obvious(word)            /* returns msg or zero if OK */
  213. char word[];                /* word to try */
  214. {
  215.     register int i = 0;        /* for length */
  216.     while (word[i]) i++;        /* compute length */
  217.     if (i < MINLENGTH) return("too short");
  218.     if (i > MAXLENGTH) return("too long");
  219.     unusual = 0;            /* no unusual triples yet */
  220.     obvword(word);            /* try the word */
  221.     if (unusual<MINNOFIND) return("too obvious");    /* too obvious */
  222.     return(0);            /* success */
  223. }
  224. /*
  225.     dotriple  --  called by obvword
  226.  
  227.     If this triple is not used by any word used to build the table,
  228.     we tally that fact.
  229. */
  230. dotriple(m1,m2,m3)
  231. short m1,m2,m3;                /* all in 0..26 */
  232. {
  233.     if (!(obvtab[m1][m2] & (1L << m3))) unusual++; /* check for triple */
  234. }
  235. /*
  236.     obvword  --  do one word
  237.  
  238.     dotriple is called on each 3-character triple in the word,
  239.     using a mapped value of the character into the range 0..26,
  240.     where letters map into 1..26 regardless of case and everything
  241.     else maps to zero.
  242. */
  243. obvword(word)
  244. char word[];                /* word to do, max 20 chars */
  245. {    register int i;            /* for loops */
  246.     register int patcnt = 0;    /* count in word */
  247.     register char ch;        /* working char */
  248.     short pat[21];            /* pattern of mapped values */
  249.     for (i=0; word[i] && (i < sizeof(pat)); i++)    /* scan until null */
  250.     {     patcnt = i;        /* max value */
  251.         ch = word[i];        /* get character */
  252.         if ((ch >= 'a') && (ch <= 'z')) pat[i] = ch + 1 - 'a';
  253.        else if ((ch >= 'A') && (ch <= 'Z')) pat[i] = ch + 1 - 'A';
  254.        else pat[i] = 0;        /* map into 0..26 */
  255.     }
  256.     for (i=0; i < patcnt - 1; i++)    /* for all triples */
  257.     {    dotriple(pat[i],pat[i+1],pat[i+2]); /* do the triple */
  258.     }
  259. }
  260.