-
Notifications
You must be signed in to change notification settings - Fork 1
/
ROOKAUTH.m
37 lines (37 loc) · 979 Bytes
/
ROOKAUTH.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
ROOKAUTH
Q
;
PWIXF(INPUT)
N HASH S HASH=$$GETCFG^ROOK("PASSWORD_HASH")
Q:HASH="PLAINTEXT" INPUT
Q:HASH="MD5" $$MD5^%ZMGWSIS(INPUT,1,1)
Q:HASH="SHA" $$SHA^%ZMGWSIS(INPUT,1,1)
Q:HASH="SHA1" $$SHA1^%ZMGWSIS(INPUT,1,1)
Q INPUT
;
ADDUSER(USERNAME,PASSWORD,ENABLED,RESULT)
N DA,OLDNEST,RET,RETUSE,RESUSE
S OLDNEST=$$CURRENTNEST^ROOK
S RET=$$USE^ROOK("INFORMATION_SCHEMA",.RESUSE)
S DA("USERS",1,"USERNAME")=USERNAME
S DA("USERS",1,"PASSWORD")=PASSWORD
S DA("USERS",1,"ENABLED")=ENABLED
S RET=$$INSERT^ROOKDM(.DA,.RESULT)
S RETUSE=$$USE^ROOK(OLDNEST,.RESUSE)
Q RET
;
AUTHUSER(USERNAME,PASSWORD)
N DA,OLDNEST,RET,RETUSE,RESUSE,HASH,RETVAL
S OLDNEST=$$CURRENTNEST^ROOK
S RET=$$USE^ROOK("INFORMATION_SCHEMA",.RESUSE)
S HASH=$$PWIXF(PASSWORD)
S RET=$$GETROWS^ROOKIDX("USERS","USERNAME",USERNAME,.DA)
I $G(DA("DATA","USERS",1,"PASSWORD"))=HASH D
. S RETVAL=1
E D
. S RETVAL=0
S RET=RKRESULT
I OLDNEST'="" D
. S RETUSE=$$USE^ROOK(OLDNEST,.RESUSE)
Q RETVAL
;