0

How to create user if i want to force user to change password for the first time login to the database?

When i using code like

CREATE USER myUser WITH PASSWORD 'mypass' VALID UNTIL current_date
ERROR:  syntax error at or near "current_date"
LINE 1: ...REATE USER myUser WITH PASSWORD 'mypass' VALID UNTIL current_da...
2
  • 1
    The value for VALID UNTIL can't be an expression, it must be a constant (e.g. valid until '2021-10-26'. But that won't "force the user to change the password" - it will simply reject any login attempt by the user if the account is expired Commented Oct 26, 2021 at 8:08
  • is any way to solve problem? Commented Oct 26, 2021 at 8:53

1 Answer 1

2

To do that, PostgreSQL would have to implement some restricted login capability which lets a person log in with an expired password, but then not let them do anything other than change the password. But it doesn't implement that. Once a password is expired, you need to get the superuser to reset it, or maybe login with some passwordless method (like locally from the database machine if configured with peer or trust) to reset it.

If you want advanced features like self-serve password resets, you should use a dedicated system like kerberos, Active Directory, etc. and hook PostgreSQL up to use them.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer! It's a pity because you can do that in MySQL and I find it very handy: ALTER USER 'we_llsee'@'%' PASSWORD EXPIRE;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.