Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while logging in with "Remember me" using Postgres #635

Closed
RomeroMsk opened this issue Feb 3, 2017 · 26 comments
Closed

Error while logging in with "Remember me" using Postgres #635

RomeroMsk opened this issue Feb 3, 2017 · 26 comments
Labels
compatibility Compatibility issue with other framework, features
Milestone

Comments

@RomeroMsk
Copy link
Contributor

With Postgres as database driver I'm having an issue when trying to log in with "Remember me" checked:

UserFrosting Application Error
The application could not run because of the following error:

Details

Type: PDOException
Code: 42883
Message: SQLSTATE[42883]: Undefined function: 7 ERROR: function sha1(unknown) does not exist LINE 1: ..., token, persistent_token, expires_at) VALUES($1, SHA1($2), ... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts.
File: .../app/vendor/birke/rememberme/src/Rememberme/Storage/PDO.php
Line: 58

So, using this library (gbirke/rememberme) makes UserFrosting database dependent.

Any chances to get a fix/workaround for this?

@alexweissman
Copy link
Member

Does Postgres not support SHA1? Is it possible that there is some extension that you need to install?

@alexweissman alexweissman added the compatibility Compatibility issue with other framework, features label Feb 4, 2017
@RomeroMsk
Copy link
Contributor Author

There is no such function in PostgreSQL, unfortunately. The only way I've found is ENCODE(DIGEST(..., 'sha1'), 'hex'), but it requires cryptographic libraries to be installed for Postgres.

@Silic0nS0ldier
Copy link
Member

Hmm. Looking at the source code, it has raw SQL queries. Wouldn't surprise me if this had issues on other dbms too.

@RomeroMsk
Copy link
Contributor Author

Yep, the code of this library doesn't seem to be DB agnostic.

@alexweissman
Copy link
Member

If we can find a pre-existing implementation of improved persistent login for Eloquent, I'd be fine if someone wants to work on replacing the gbirke library. Otherwise, we may have to implement our own version.

@alexweissman alexweissman modified the milestone: 4.0 Mar 1, 2017
@RomeroMsk
Copy link
Contributor Author

I think the easiest way to fix this will be own implementation of PDO storage class for gbirke/rememberme library:

  1. Create a corresponding PHP script in app/sprinkles/account/src dir.
  2. Copy the existing code from vendor/birke/rememberme/src/Rememberme/Storage/PDO.php and replace all SHA1() in SQL queries with PHP sha1() function calls.
  3. Use this new file in UserFrosting\Sprinkle\Account\Authenticate\Authenticator class instead of Birke\Rememberme\Storage\PDO.

@alexweissman
Copy link
Member

Did you see this commit: gbirke/rememberme#20 (comment) ?
Not sure if that solves the problem with Postgres as well.

My recommendation would be to fork @gbirke's repo, make the changes, and then submit a PR. He seems pretty willing to merge PRs as long as they adhere to standards and pass unit tests. It would be simpler than for us to try and maintain a separate fork.

@RomeroMsk
Copy link
Contributor Author

RomeroMsk commented Mar 7, 2017

I didn't see this commit itself yet, but I saw this solution with custom SHA1 function before. Unfortunately, it requires an additional Postgresql module to be installed. I'm going to check it when I will be able to get this module installed.
But anyways it is still a compatibility issue that makes your product DB dependent ;)

@alexweissman
Copy link
Member

Maybe leave a comment on that commit? Ask them why they didn't just use PHP's sha1 function instead?

@RomeroMsk
Copy link
Contributor Author

There is an issue already (from me): gbirke/rememberme#19
It was mentioned in that comment, btw.

@gbirke
Copy link

gbirke commented Mar 7, 2017

The history why I do the hashing in SQL instead of PHP is a bit hazy (that was 2-3 years ago), I dimly remember having problems writing a unit test and then settling on doing it in SQL because it was the easiest. At the moment I have no spare time to change it, but if anyone supplies a patch, I'll gladly merge it and release a new version of the library.

@RomeroMsk
Copy link
Contributor Author

Well, to test a patch with UF we need to bump the version of gbirke/rememberme used in UF to the latest one.

@Silic0nS0ldier
Copy link
Member

Not necessarily. Assuming we are already using the latest version (and therefore there are no breaking changes), its possible to just replace the respective folder in vendor with the updated source. (prevents usage of composer, but fine for testing purposes).

I believe there is also a way of forcing composer to use grab a specific version, regardless of what other dependencies request. (fairly sure I've done this before, not that I remember how...)

@RomeroMsk
Copy link
Contributor Author

UF uses version 1.0.4. The latest is 2.0. And there are breaking changes (at least with storage classes naming). So the problem is if someone will make a patch for the current version of gbirke/rememberme and @gbirke will release a new version, it will not affect the UF.

@RomeroMsk
Copy link
Contributor Author

I'm going to check it when I will be able to get this module installed.

After installing the module and adding the SHA1 function to Postgresql I still have an issue while logging in with "Remember me". This time we have a problem with IF:

UserFrosting Application Error
The application could not run because of the following error:

Details

Type: PDOException
Code: 42883
Message: SQLSTATE[42883]: Undefined function: 7 ERROR: function if(boolean, integer, integer) does not exist LINE 1: SELECT IF(SHA1($1) = token, 1, -1) AS token_match FROM uf_pe... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts.
File: .../app/vendor/birke/rememberme/src/Rememberme/Storage/PDO.php
Line: 32

This was solved in gbirke/rememberme#20 PR mentioned earlier, but to use this fix we (again) need the latest version of gbirke/rememberme.

@alexweissman
Copy link
Member

We can talk about updating UF to use gbirke/rememberme 2.0. Can you join us in chat?

@RomeroMsk
Copy link
Contributor Author

Yes, I can. Please invite me (romeromsk) to the channel related to this topic.

@alexweissman
Copy link
Member

Cool, want to talk about it in #general?

@RomeroMsk
Copy link
Contributor Author

@gbirke would you please add the 2.0 version/tag, so we can update the composer dependency?

@gbirke
Copy link

gbirke commented Mar 15, 2017

I have created the 2.0.1 release which uses PHPs sha1 function instead of the SQL one.

@RomeroMsk
Copy link
Contributor Author

Great, tnx @gbirke.
@alexweissman, so now we just need to check it all together. Please change the birke/rememberme version to 2.0.1 in composer.json after reviewing my changes.

@alexweissman
Copy link
Member

Cool, I might be able to do it tonight. Btw, you can actually make the change directly and commit to the same branch, and the PR should get updated.

@RomeroMsk
Copy link
Contributor Author

Ok, done.

@RomeroMsk
Copy link
Contributor Author

@alexweissman, would you please merge it today?

@alexweissman
Copy link
Member

Alright, done! See 9c9316b.

@RomeroMsk
Copy link
Contributor Author

Tested after deleting the custom SHA1() Postgres function, works. Thanks, @alexweissman and @gbirke!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility Compatibility issue with other framework, features
Projects
None yet
Development

No branches or pull requests

4 participants