Search code examples
mysqlauthenticationpasswords

Is it possible to authenticate at the same time as making a SQL query (not authenticate beforehand)


This may be a horrible idea for security but I am wondering if there is a way to authenticate an existing SQL user at the same time as making a SQL query.

e.g.

SELECT * FROM mytable WHERE city <> 'Detroit' and ...

After the ellipses should be the part where the user is authenticated. It it possible to do this in one step?

I am trying to provide useful error messages but unfortunately I am stuck using SOAP and I am having a hard time proving a user exists before making the query. Please let me know if I am totally going the wrong direction. I can get nice error messages if the database doesn't exist, but I just get vague SOAP errors if the user / password are incorrect. I would like to prove that the user / password are acceptable before making the query so I can make my program more user friendly.

Thanks in advance.


Solution

  • You can from shell command line:

    $ mysql -u user -p -e 'show databases;'
    

    Just to be clear: there's NO WAY to execute a query BEFORE authentication only if maybe you use a API without auth but that is a huge security risk.