2

I am trying to reset password for all users with following psql command. The command executes successfully but the value of password is wrong. The password is bcrypt string of 12345

psql -U myuser -d mydb -c "update \"Users\" set \"PASSWORD\" = '$2a$10$u0vd9noCisUUJME9k4daU.1/TNBPaeQam8dnV6tUOWwjn4kFT5XdW'"

The query:

select "PASSWORD" from "Users"; 

returns:

a.1/TNBPaeQam8dnV6tUOWwjn4kFT5XdW

instead of:

$2a$10$u0vd9noCisUUJME9k4daU.1/TNBPaeQam8dnV6tUOWwjn4kFT5XdW 

What I understand that postgres is taking $ as a placeholder or special character. How can I escape it?

1 Answer 1

3

The problem is not with postgres but with the shell. It interprets the dollar signs as beginning of variables. You should escape them wit a backslash ('\$2a\$10\$u0vd9noCisUUJME9k4daU.1/TNBPaeQam8dnV6tUOWwjn4kFT5XdW'):

psql -U myuser -d mydb -c "update \"Users\" set \"PASSWORD\" = '\$2a\$10\$u0vd9noCisUUJME9k4daU.1/TNBPaeQam8dnV6tUOWwjn4kFT5XdW'"
Sign up to request clarification or add additional context in comments.

2 Comments

Bingo, thanks a lot @macmoonshine, works perfectly :)
You're wellcome. BTW.: The pgcrypto module from pgcontrib offers a stored function for this encryption as well.

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.