當新增使用者或更改使用者密碼時, 如何產生使用者動態密碼 ?
當系統管理者新增使用者或更改使用者密碼時, 如何產生使用者動態密碼 ?
由於新增使用者時,系統的預設密碼為使用者代碼,或使用者密碼錯誤次數超過系統值
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
A blog about IBM i (AS/400), MQ and other things developers or Admins need to know.
星期四, 11月 02, 2023
2002-10-24 當新增使用者或更改使用者密碼時, 如何產生使用者動態密碼 ?(Create dynamic password)
2002-09-12 如何於應用軟體中確認使用者密碼?
如何於應用軟體中確認使用者密碼?
在 如何於 RPG 中確認使用者密碼(Verifying Password in RPG) ? 電子報中,我已說明
如何利用 API 作密碼驗證,如果您覺得複雜,這裡我再提供一個簡單的方法,但這個方法無法
辨別其他使用者的密碼,只能確認使用者自己的密碼,所以並不適合有授權他人的作業使用。
這個方法是利用指令 CHKPWD (Check Password) 來完成使用者密碼認證作業。
File : QDDSSRC
Member: CHKPWDD
Type : DSPF
Usage : CRTDSPF CHKPWDD
A DSPSIZ(24 80 *DS3)
A CA03(03 'EXIT')
A R SCRN01
A 4 6'ENTER YOUR PASSWORD TO -
A CONTINUE:'
A PWD 10A I 4 40
A DSPATR(ND)
A 23 2'F3 = EXIT'
A MSG 78 24 2
File : QCLSRC
Member: CHKPWDC
Type : CLP
Usage : CRTCLPGM CHKPWDC
CALL CHKPWDC
PGM
DCLF FILE(CHKPWDD)
RETRY:
SNDRCVF
CHGVAR &MSG ' '
IF (&IN03 = '1') GOTO END
CHKPWD PASSWORD(&PWD)
MONMSG MSGID(CPF2362 CPF2363 CPF2364) EXEC(DO)
RCVMSG MSGTYPE(*LAST) RMV(*NO) MSG(&MSG)
GOTO RETRY
ENDDO
END:
ENDPGM
訂閱:
文章 (Atom)