Software / code / prosody
Comparison
plugins/mod_auth_internal_plain.lua @ 12646:3f38f4735c7a
usermanager, mod_auth_*: Add get_account_info() returning creation/update time
This is useful for a number of things. For example, listing users that need to
rotate their passwords after some event. It also provides a safer way for code
to determine that a user password has changed without needing to set a handler
for the password change event (which is a more fragile approach).
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 12 Jul 2022 13:14:47 +0100 |
| parent | 11544:c98aebe601f9 |
| child | 12950:2cb5994e3f94 |
comparison
equal
deleted
inserted
replaced
| 12645:a741183eec97 | 12646:3f38f4735c7a |
|---|---|
| 46 return nil, "Password fails SASLprep."; | 46 return nil, "Password fails SASLprep."; |
| 47 end | 47 end |
| 48 local account = accounts:get(username); | 48 local account = accounts:get(username); |
| 49 if account then | 49 if account then |
| 50 account.password = password; | 50 account.password = password; |
| 51 account.updated = os.time(); | |
| 51 return accounts:set(username, account); | 52 return accounts:set(username, account); |
| 52 end | 53 end |
| 53 return nil, "Account not available."; | 54 return nil, "Account not available."; |
| 55 end | |
| 56 | |
| 57 function provider.get_account_info(username) | |
| 58 local account = accounts:get(username); | |
| 59 if not account then return nil, "Account not available"; end | |
| 60 return { | |
| 61 created = account.created; | |
| 62 password_updated = account.updated; | |
| 63 }; | |
| 54 end | 64 end |
| 55 | 65 |
| 56 function provider.user_exists(username) | 66 function provider.user_exists(username) |
| 57 local account = accounts:get(username); | 67 local account = accounts:get(username); |
| 58 if not account then | 68 if not account then |
| 69 function provider.create_user(username, password) | 79 function provider.create_user(username, password) |
| 70 password = saslprep(password); | 80 password = saslprep(password); |
| 71 if not password then | 81 if not password then |
| 72 return nil, "Password fails SASLprep."; | 82 return nil, "Password fails SASLprep."; |
| 73 end | 83 end |
| 74 return accounts:set(username, {password = password}); | 84 local now = os.time(); |
| 85 return accounts:set(username, { | |
| 86 password = password; | |
| 87 created = now, updated = now; | |
| 88 }); | |
| 75 end | 89 end |
| 76 | 90 |
| 77 function provider.delete_user(username) | 91 function provider.delete_user(username) |
| 78 return accounts:set(username, nil); | 92 return accounts:set(username, nil); |
| 79 end | 93 end |