Skip to content

Commit

Permalink
Add: ExpDays 密碼有效期限, 超過時間必須更改密碼才能登入. 0=不限; 若有設定非0, 則登入成功訊息增加 "|ExpDay…
Browse files Browse the repository at this point in the history
…s=|ExpDate=";
  • Loading branch information
fonwin committed Feb 15, 2024
1 parent c71492c commit c9950e3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 12 additions & 1 deletion fon9/auth/UserMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 25,8 @@ static void SerializeVer(Archive& ar, ArchiveWorker<Archive, UserRec>& rec, unsi
rec.EvLastErr_.From_,
rec.ErrCount_,
rec.UserFlags_,
rec.AuthcList_
rec.AuthcList_,
rec.ExpDays_
);
}

Expand Down Expand Up @@ -111,6 112,7 @@ seed::Fields UserMgr::MakeFields() {
fields.Add(fon9_MakeField2(UserRec, AuthcList));
fields.Add(fon9_MakeField2(UserRec, NotBefore));
fields.Add(fon9_MakeField2(UserRec, NotAfter));
fields.Add(fon9_MakeField2(UserRec, ExpDays));

fields.Add(fon9_MakeField (UserRec, EvChgPass_.Time_, "ChgPassTime"));
fields.Add(fon9_MakeField (UserRec, EvChgPass_.From_, "ChgPassFrom"));
Expand Down Expand Up @@ -204,6 206,15 @@ AuthR UserTree::AuthUpdate(fon9_Auth_R rcode, const AuthRequest& req, AuthResult
RevBufferList rbuf{128};
if (!authr.AuthzId_.empty())
RevPrint(rbuf, "|ForAuthc=", authr.AuthcId_);
if (user->ExpDays_) {
TimeStamp expDate = ((user->EvChgPass_.Time_.IsNullOrZero() || rcode == fon9_Auth_PassChanged)
? now
: (user->EvChgPass_.Time_ TimeInterval_Day(user->ExpDays_)));
expDate = GetLocalTimeZoneOffset();
RevPrint(rbuf, "|ExpDays=", user->ExpDays_, "|ExpDate=", expDate, FmtTS{"K"});
if (GetYYYYMMDD(now GetLocalTimeZoneOffset()) > GetYYYYMMDD(expDate))
user->UserFlags_ |= UserFlags::NeedChgPass;
}
RevPrint(rbuf,
"Last logon: ", user->EvLastAuth_.Time_, kFmtYsMsD_HH_MM_SS_L,
" from ", user->EvLastAuth_.From_,
Expand Down
5 changes: 4 additions & 1 deletion fon9/auth/UserMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 93,10 @@ struct fon9_API UserRec : public PolicyItem {
UserEv EvLastErr_;
/// 密碼錯誤次數, 一旦認證成功(或改密碼成功)此值會歸零.
uint8_t ErrCount_ = 0;
uint8_t Padding_FilledForAlign___[3];
/// 密碼有效期限, 超過時間必須更改密碼才能登入.
/// 0=不限;
uint8_t ExpDays_ = 0;
uint8_t Padding_FilledForAlign___[2];
UserFlags UserFlags_ = UserFlags::NeedChgPass;
/// 配合 UserFlags::AllowBeAuthz; 檢查: 有哪些 authc 允許使用此 UserRec 當成 authz;
/// 使用 ';' 分隔, 不理會空白;
Expand Down

0 comments on commit c9950e3

Please sign in to comment.