user10252822
user10252822

Reputation:

Postgresql - password authentication failed for user

Well, I've been working on a project on Django, but a friend of mine was facing a problem so he sent me his project (The entire folder). Anyway, I tried to run the server but it didn't work. I tried to change the password and the username from the settings file, and when I tried to access the user, the username was changed (as the sql shell recognized it, I think ¯_(ツ)_/¯), but whenever I try to login with the password I wrote in the settings file it produces the following error:

django.db.utils.OperationalError: FATAL: password authentication failed for user "Youssef"

Here's the DATABASE part in the settings.py file:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'Boards_django',
        'USER': 'Youssef',
        'PASSWORD': '000000',
        'HOST': 'localhost',
        'PORT': '5432',
    }
}

BTW, the database is recognized by the PgAdmin4:

enter image description here

Any idea what should I do???

Side note: I can't access the user, hence I'm not able to use any of the commands of postgresql Also, when I try to run the server or make anything on the database from VS Code, It raises the following error:

django.db.utils.OperationalError: FATAL: password authentication failed for user "Youssef"

Here's the data in the pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     scram-sha-256
# IPv4 local connections:
host    all             all             127.0.0.1/32            scram-sha-256
# IPv6 local connections:
host    all             all             ::1/128                 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     scram-sha-256
host    replication     all             127.0.0.1/32            scram-sha-256
host    replication     all             ::1/128                 scram-sha-256

Upvotes: 1

Views: 3427

Answers (2)

user10252822
user10252822

Reputation:

well, the problem was that my friend had a slight spelling difference in his database, when I added it to my databases in the PgAdmin page, It worked perfectly.

Thanks to anyone who tried to help

Upvotes: 0

Laurenz Albe
Laurenz Albe

Reputation: 247645

There are several possibilities:

  • you used the wrong password

  • there is no SCRAM-SHA-256 password set for the user

    This could be either because no password is set, or because the password_encryption parameter is set to md5, or because the password has not been changed after password_encryption was changed.

    To see the current setting:

    SHOW password_encryption;
    

    To see the password:

    SELECT rolpassword
    FROM pg_authid
    WHERE rolname = 'Youssef';
    

Upvotes: 1

Related Questions