You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Presently, there is no way for an instructor to learn if/when a student (last) changed their password. I wonder if an event trigger or a log entry provides the information required to discover pwd-change activity.
I found two potential ways of doing this, but neither is 100% ideal:
Store the MD5 hash of the initial password that was set for the user. That way, it would be possible to compare it to the hash of the current password from pg_authid to see if it was changed. This would also allow a password reset function to reset the password to the actual "initial password", if one was given. (Instead of only being capable of resetting it to an ID/username.)
The xmin column stores the transaction id of the transaction that last modified a certain row. The pg_authid system table also has an xmin column. We can store the value of the xmin column from the initial role creation, and compare it to the current value to see if the role has been modified. We could also update the stored xmin value whenever a password is reset.
Both of these solutions require read access to the pg_authid table, which is only available to superuser roles. Also, these solutions only tell if a student changed their password, not when.
Overall, the first solution seems to be a bit better since it provides extra functionality to a passwordReset function. However, it does take up a bit more storage space since the entire MD5 hash has to be stored (32 chars). Also, the second solution would incorrectly report that the password has been changed if the corresponding row in pg_authid was modified for another reason, or if a user happen to change their password to the same password.
I like Approach 1 @afig lists. A function such as isInitialPassword(username) (not sure of the function's name) is probably also required to test if a user's current pwd is the same as the initial pwd.
If we don't want to store the pwd (and I don't prefer storing it), the proposed function can just test the current pwd against user name with the assumption that the initial password is always the user name.
When you say not storing the passwords, are you referring to just the cleartext password or also the MD5 hashes? If we assume that the initial password is always the username and do not store even the MD5 hashes, then the isInitialPassword function will not be able to check for a pw change if an initial password was given during user creation, which could create confusion.
Another issue with checking with just the username is that the MD5 hash appears to have a salt added. It seems to be the password concatenated with the username, however we should confirm if this is documented somewhere:
postgres=# ALTER ROLE role1 ENCRYPTED PASSWORD 'password';
ALTER ROLE
postgres=# SELECT rolname, rolpassword FROM pg_authid WHERE rolname = 'role1';
rolname | rolpassword
---------+-------------------------------------
role1 | md53cc7f7650262f2d46c81337be1b76ec4
(1 row)
postgres=# SELECT md5('password');
md5
----------------------------------
5f4dcc3b5aa765d61d8327deb882cf99
(1 row)
postgres=# SELECT md5('passwordrole1');
md5
----------------------------------
3cc7f7650262f2d46c81337be1b76ec4
(1 row)
On a related note, PostgreSQL 10 (expected to be released in Sep 2017) removes support for unencrypted passwords, so we should not create a solution that relies on being able to check for an unencrypted password in pg_authid.
I meant storing the pwd's hash. Because us storing pwd in any form is a security risk and after learning that Postgres stores pwd hash with a salt, I propose we consider triggers or logs to determine if/when pwd was last changed.
After using ClassDB for the last few months, I feel it is OK if it is not possible to know when a pwd was last changed: It can be helpful to know, but it is not necessary.
Activity
afig commentedon Jun 19, 2017
I found two potential ways of doing this, but neither is 100% ideal:
Store the MD5 hash of the initial password that was set for the user. That way, it would be possible to compare it to the hash of the current password from
pg_authidto see if it was changed. This would also allow a password reset function to reset the password to the actual "initial password", if one was given. (Instead of only being capable of resetting it to an ID/username.)The
xmincolumn stores the transaction id of the transaction that last modified a certain row. Thepg_authidsystem table also has anxmincolumn. We can store the value of thexmincolumn from the initial role creation, and compare it to the current value to see if the role has been modified. We could also update the storedxminvalue whenever a password is reset.Both of these solutions require read access to the
pg_authidtable, which is only available tosuperuserroles. Also, these solutions only tell if a student changed their password, not when.Overall, the first solution seems to be a bit better since it provides extra functionality to a passwordReset function. However, it does take up a bit more storage space since the entire MD5 hash has to be stored (32 chars). Also, the second solution would incorrectly report that the password has been changed if the corresponding row in
pg_authidwas modified for another reason, or if a user happen to change their password to the same password.smurthys commentedon Jun 22, 2017
I like Approach 1 @afig lists. A function such as
isInitialPassword(username)(not sure of the function's name) is probably also required to test if a user's current pwd is the same as the initial pwd.If we don't want to store the pwd (and I don't prefer storing it), the proposed function can just test the current pwd against user name with the assumption that the initial password is always the user name.
Vote.
afig commentedon Jun 23, 2017
I also prefer the first approach.
When you say not storing the passwords, are you referring to just the cleartext password or also the MD5 hashes? If we assume that the initial password is always the username and do not store even the MD5 hashes, then the
isInitialPasswordfunction will not be able to check for a pw change if an initial password was given during user creation, which could create confusion.Another issue with checking with just the username is that the MD5 hash appears to have a salt added. It seems to be the password concatenated with the username, however we should confirm if this is documented somewhere:
On a related note, PostgreSQL 10 (expected to be released in Sep 2017) removes support for unencrypted passwords, so we should not create a solution that relies on being able to check for an unencrypted password in
pg_authid.smurthys commentedon Jun 25, 2017
I meant storing the pwd's hash. Because us storing pwd in any form is a security risk and after learning that Postgres stores pwd hash with a salt, I propose we consider triggers or logs to determine if/when pwd was last changed.
smurthys commentedon Dec 28, 2017
After using ClassDB for the last few months, I feel it is OK if it is not possible to know when a pwd was last changed: It can be helpful to know, but it is not necessary.