星期四, 11月 02, 2023

2002-10-24 當新增使用者或更改使用者密碼時, 如何產生使用者動態密碼 ?(Create dynamic password)


當新增使用者或更改使用者密碼時, 如何產生使用者動態密碼 ?

當系統管理者新增使用者或更改使用者密碼時, 如何產生使用者動態密碼 ?

由於新增使用者時,系統的預設密碼為使用者代碼,或使用者密碼錯誤次數超過系統值
QMAXSIGN 的設定值時,系統會將使用者設為失效,或使用者密碼忘記時,這些狀況均
需要重設密碼,此時若使用系統預設值 PASSWORD(*USRPRF) 是很危險的,因為使用者若
未即時更改預設密碼(此時密碼與使用者代碼相同),就會給與不肖人士有機會入傾系統,
造成系統安全漏洞, 所以需要有一支能
產生動態密碼的程式,來產生使用者密碼,但產生的密碼要好記,不然使用者很容易忘記.
這裡提供一個範例,你可依照自己的需求更改.


File  : QRPGLESRC
Member: GENPWDR
Type  : RPGLE
OS/400 Version: V3R1 以後
Usage : CRTBNDRPG GENPWDR
        CALL GENPWDR 按 Enter,若回 'N','n' 停止執行,否則每按一次 Enter,產生一個密碼.



      * Scott Klement [klemscot@klements.com]

     H DFTACTGRP(*NO) BNDDIR('QC2LE')

     D srand           PR                  extproc('srand')
     D   seed                        10U 0 value
     D rand            PR            10I 0 extproc('rand')
     D consonant       PR             1A
     D vowel           PR             1A

     D dsTS            DS
     D   dsTS_1                        Z
     d   dsTS_Date                   10A   overlay(dsTS_1:1)
     d   dsTS_Time                    8A   overlay(dsTS_1:12)
     d   dsTS_Milli                   6A   overlay(dsTS_1:21)
     d   dsTS_sec1                    1A   overlay(dsTS_Time:7)
     d   dsTS_sec2                    1A   overlay(dsTS_Time:8)
     d   dsTS_ms1                     1A   overlay(dsTS_Milli:1)
     d   dsTS_ms2                     1A   overlay(dsTS_Milli:2)
     d   dsTS_ms3                     1A   overlay(dsTS_Milli:3)

     D dsSeed          DS
     D   dsSeed_1                     5S 0 inz(0)
     D   dsSeed_2                     2S 0 overlay(dsSeed_1:1)
     D   dsSeed_ms3                   1A   overlay(dsSeed_1:1)
     D   dsSeed_ms1                   1A   overlay(dsSeed_1:2)
     D   dsSeed_sec2                  1A   overlay(dsSeed_1:3)
     D   dsSeed_sec1                  1A   overlay(dsSeed_1:4)
     D   dsSeed_ms2                   1A   overlay(dsSeed_1:5)

     D wkMsg           S             50A
     D wkReply         S              1A

     C****************************************************************
     C* Mangle the time, and use it to seed the random number generator
     C****************************************************************
     c                   time                    dsTS_1

     c                   eval      dsSeed_ms1 = dsTS_ms1
     c                   eval      dsSeed_ms2 = dsTS_ms2
     c                   eval      dsSeed_ms3 = dsTS_ms3
     c                   eval      dsSeed_sec1 = dsTS_sec1
     c                   eval      dsSeed_sec2 = dsTS_sec2

     c                   dow       dsSeed_2 > 31
     c                   eval      dsSeed_2 = dsSeed_2 - 31
     c                   enddo

     c                   callp     srand(dsSeed_1)

     C****************************************************************
     C* Make a password that consists of 7 chars, consonants and
     C* vowels every other char
     C****************************************************************
     c                   dou       wkReply='N' or wkReply='n'

     c                   eval      wkMsg = 'Password = ' +
     c                                      consonant +
     c                                      vowel +
     c                                      consonant +
     c                                      vowel +
     c                                      consonant  +
     c                                      vowel +
     c                                      consonant  +
     c                                      '  Calculate another?'

     c     wkMsg         dsply                   wkReply

     c                   enddo

     c                   eval      *inlr = *on


      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      *  this returns a random consonant
      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P consonant       B
     D consonant       PI             1A
     D x               S             10I 0
     D c               S             21A   INZ('BCDFGHJKLMNPQRSTVWXZ')
     c                   eval      x = %rem(rand: 20) + 1
     c                   return    %subst(c:x:1)
     P                 E


      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      *  this returns a random vowel
      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P vowel           B
     D vowel           PI             1A
     D x               S             10I 0
     D v               S             21A   INZ('AEIOUY')
     c                   eval      x = %rem(rand: 6) + 1
     c                   return    %subst(v:x:1)
     P                 E



沒有留言: