Mercurial > prosody-hg
comparison plugins/mod_auth_internal_hashed.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 |
| parents | a0ff5c438e9d |
| children | aed38948791f |
comparison
equal
deleted
inserted
replaced
| 12645:a741183eec97 | 12646:3f38f4735c7a |
|---|---|
| 84 | 84 |
| 85 account.stored_key = stored_key_hex | 85 account.stored_key = stored_key_hex |
| 86 account.server_key = server_key_hex | 86 account.server_key = server_key_hex |
| 87 | 87 |
| 88 account.password = nil; | 88 account.password = nil; |
| 89 account.updated = os.time(); | |
| 89 return accounts:set(username, account); | 90 return accounts:set(username, account); |
| 90 end | 91 end |
| 91 return nil, "Account not available."; | 92 return nil, "Account not available."; |
| 93 end | |
| 94 | |
| 95 function provider.get_account_info(username) | |
| 96 local account = accounts:get(username); | |
| 97 if not account then return nil, "Account not available"; end | |
| 98 return { | |
| 99 created = account.created; | |
| 100 password_updated = account.updated; | |
| 101 }; | |
| 92 end | 102 end |
| 93 | 103 |
| 94 function provider.user_exists(username) | 104 function provider.user_exists(username) |
| 95 local account = accounts:get(username); | 105 local account = accounts:get(username); |
| 96 if not account then | 106 if not account then |
| 113 if not valid then | 123 if not valid then |
| 114 return valid, stored_key; | 124 return valid, stored_key; |
| 115 end | 125 end |
| 116 local stored_key_hex = to_hex(stored_key); | 126 local stored_key_hex = to_hex(stored_key); |
| 117 local server_key_hex = to_hex(server_key); | 127 local server_key_hex = to_hex(server_key); |
| 128 local now = os.time(); | |
| 118 return accounts:set(username, { | 129 return accounts:set(username, { |
| 119 stored_key = stored_key_hex, server_key = server_key_hex, | 130 stored_key = stored_key_hex, server_key = server_key_hex, |
| 120 salt = salt, iteration_count = default_iteration_count | 131 salt = salt, iteration_count = default_iteration_count, |
| 132 created = now, updated = now; | |
| 121 }); | 133 }); |
| 122 end | 134 end |
| 123 | 135 |
| 124 function provider.delete_user(username) | 136 function provider.delete_user(username) |
| 125 return accounts:set(username, nil); | 137 return accounts:set(username, nil); |
