8

I already asked a question about this 2 days ago, here are the links Got "password authentication failed for user" but in pgAdmin 3 its working

But I still didn't get an answer to solve the problem.

So I tried to create a new laravel project, then edit the .env file, check if php artisan migrate can run.

After I run php artisan migrate it's running, so it means that my credentials to PostgreSQL database are correct right? if not it will tell you password authentication failed for user "postgres", but I don't get any error at all, so I go to the next step. Now after I make sure everything is OK i run php artisan make:auth, it's a success without error at all, so I go to the web browser then run the site, I clicked the register / login button, fill the fields, submit then, it's happened again the nightmare

I got this message from the website

SQLSTATE[08006] [7] FATAL: password authentication failed for user "postgres" FATAL: password authentication failed for user "postgres" (SQL: select count(*) as aggregate from "users" where "email" = test@test.com)

Even though php artisan migrate run really well, so I've no idea why it's happening. Is there somebody that ever run into this problem before? or maybe why it's happening?

I already search all keywords that possible to fix this problem, but I can't found the answer, it's really stressed me out.

for the info I'm using:

PostgreSQL 9.6.8

Laravel 5.6

Ubuntu 17.10

Edited: Here is my pg_hba.conf

enter image description here

Community
  • 1
  • 1
  • Have you checked this [answer](https://stackoverflow.com/questions/11972121/cannot-connect-to-pgsql-via-laravel-sqlstate08006-7-fatal)? – Taacoo Mar 19 '18 at 09:22
  • Try after clearing the configurations cache – ManiMuthuPandi Mar 19 '18 at 09:23
  • @Taacoo I already tried it before – Khrisna Gunanasurya Mar 19 '18 at 09:30
  • @ManiMuthuPandi I already tried it so many times when it's happening for the first time – Khrisna Gunanasurya Mar 19 '18 at 09:31
  • @KhrisnaGunanasurya | Hope this solution is worked https://askubuntu.com/questions/413585/postgres-password-authentication-fails Please check and acknowledge to me. – Chintan Kotadiya Mar 30 '18 at 09:08
  • @chintankotadiya I already tried it actually, but it's not working, even before I tried to use that method, I can use the php migrate from the terminal and without problem, if there's a problem with the password, the error will be showed in the terminal too as far as I know, thanks for the suggestion anyway – Khrisna Gunanasurya Mar 30 '18 at 13:45
  • can you post your user table migration file, model, RegisterController and LoginController? Because you have tried enough with the credentials so now we need to check the code if that could be the reason behind this error. – Parth Pandya Apr 04 '18 at 06:23
  • @parthu_panther Well I use the default, I haven't changed anything, I only use `php artisan make:auth` that's all, haven't change anything yet, only the `.ENV` file and the `database.php`. But I think I just gonna use mysql then, until there are updates from the official site – Khrisna Gunanasurya Apr 04 '18 at 06:26
  • specifically when does this error show offs? I mean during register or login? – Parth Pandya Apr 04 '18 at 06:29
  • @parthu_panther both of them and when I tried to call a data with a controller it does the same, so I think the problem is not from the make:auth, but from the psql driver or something – Khrisna Gunanasurya Apr 04 '18 at 06:30
  • ohkay. can you show the `pg_hba.conf` file? – Parth Pandya Apr 04 '18 at 06:41
  • @parthu_panther Hi, it's there now, I already updated my question – Khrisna Gunanasurya Apr 04 '18 at 11:22
  • instead of `md5` and `peer` try with `password`. restart the server again and try. Acknowledge me if it work or we shall try a different workaround. – Parth Pandya Apr 04 '18 at 11:31
  • @parthu_panther the problem is still exist – Khrisna Gunanasurya Apr 04 '18 at 11:37
  • @parthu_panther it doesn't fix it. – Khrisna Gunanasurya Apr 04 '18 at 11:37
  • ohkay than go with `trust`. instead of `md5` and `peer` try with `trust`.dont forget to reload the configurations – Parth Pandya Apr 04 '18 at 11:38
  • @parthu_panther nah it still doesn't fix it, I think the problem is somewhere in Laravel> – Khrisna Gunanasurya Apr 04 '18 at 11:42
  • this two questions are somewhat related to your problem. kindly look into them if they could be helpful. [No: 1](https://askubuntu.com/questions/413585/postgres-password-authentication-fails) & [No: 2](https://stackoverflow.com/questions/2942485/psql-fatal-ident-authentication-failed-for-user-postgres) – Parth Pandya Apr 04 '18 at 11:49
  • @parthu_panther I already tried No.1 before but it's not working, and for the No 2, I just tried it and hope it worked, but it doesn't. I wonder why does this happened? have you ever got this problem too? – Khrisna Gunanasurya Apr 04 '18 at 12:05
  • no. i use mysql. never used pg_sql. – Parth Pandya Apr 04 '18 at 12:44
  • @parthu_panther Ah I see, but still thanks for the helps, I appreciate it so much :D – Khrisna Gunanasurya Apr 04 '18 at 12:49
  • 1
    community has given me so much so I would always love to give back whatever is possible. btw its my pleasure. may you find the errors as soon as possible. – Parth Pandya Apr 04 '18 at 12:51
  • 1
    @parthu_panther that's really nice of you – Khrisna Gunanasurya Apr 04 '18 at 12:52
  • kind actions always have kind reactions. – Parth Pandya Apr 04 '18 at 12:54
  • set under `database administrative login by unix ...` the local of `postgres` to `trust` + under `local is for unix domain socket ...` the local to `trust` + under `ipv4 local connections` the host to `trust`, then use the command `sudo service postgresql restart`. Then typq `psql -h localhost ` to see if you can directly connect to the db from the commandline. – King Reload Apr 05 '18 at 11:29
  • Check your cli and browser versions, I think they are different, because migrate work with cli config, and it work correct, maybe problem with you php configurations. Please check it. – Vahe Galstyan Apr 05 '18 at 13:20
  • @KingReload Hi, sorry for the long answer, just out of the town and didn't have internet connection. I'll try it later when I at home – Khrisna Gunanasurya Apr 09 '18 at 01:48
  • @VaheGalstyan now that you mention it, I just remember that my postgresql version on the vagrant is `10` but in my computer it's `9.6`, and all this time I always edit on the vagrant, should I do it on local postgres? or it's correct to edit it on the vagrant? – Khrisna Gunanasurya Apr 09 '18 at 01:50

2 Answers2

2

Check your database.php file in config directory, and check the pgsql array. If accessing DB credential values from .env not worked there, test it by directly putting credentials there. hope it will help. Artisan commands work by accessing the credentials from .env files directly,not from database.php that's why migration worked.

Nithin John
  • 897
  • 3
  • 8
  • 21
  • I already set the env and the database.php, I had this problem for about 3 days before I ask it on SO. but the problem is only the laravel can't access psql database – Khrisna Gunanasurya Mar 30 '18 at 13:41
  • Do you changed default connection in database.php. 'default' => env('DB_CONNECTION', 'pgsql'), – Nithin John Mar 30 '18 at 13:50
  • Yes I already do that, and set the vars to the correct login credential (I can use this credential with pgAdmin, and even I can use php artisan migrate, with only set the env file, so I believe there are no problem with the env file or the credential) – Khrisna Gunanasurya Mar 30 '18 at 13:53
  • Put username and password directly into database.php, Check whether it working or not. – Nithin John Mar 30 '18 at 13:55
  • If that's not worked just clear your config and cache. php artisan config:clear php artisan cache:clear – Nithin John Mar 30 '18 at 14:07
  • well I already done that one as well, several times, I even already re-install vagrant & VM, and the postgreSQL as well, I think I already tried everything I can found on the google, because I stuck with this problem for about 1 week without getting any answer, I even asked on laracasts forum but didn't get the answer to fix it. So I think laravel 9.6 had a bug for the psql database, but well that's just my assumption – Khrisna Gunanasurya Mar 30 '18 at 14:18
  • Go to vendor/laravel/framework/src/Illuminate/Database/Connectors/PostgresConnector.php Check public function connect(array $config), just dd $config there, see what happens there – Nithin John Mar 30 '18 at 14:27
  • it says the driver is pgsql, the host, port, etc are correct settings, the schema is public which is correct, `sslmode` is prefer (I don't know if it's correct or not) and the name is pgsql as well – Khrisna Gunanasurya Mar 31 '18 at 03:44
0

I had a similar problem, my generated password contained the character: '#'. This made it a comment line, ignoring the rest of the password. I just changed my password.