Checking password with mysql & PASSWORD()

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Checking password with mysql & PASSWORD()

    In my mysql database, I've stored all the passwords using the PASSWORD()
    function. Now I'm running a test and need to compare the password in my php
    document to that saved in the database. I used the string

    "Select name From users Where password = PASSWORD('$testPass')"

    and ran mysql_query() using the string. But nothing was returned. So I
    decided to run a test and try to change a password from my php page using
    the string

    Update users Set password = PASSWORD('$newPass') Where name = 'userName1'"

    and it works fine. My database is updated properly. So my question is, why
    can't I find a match using the PASSWORD function, but can still update my
    table?





    John Victor Guest

  2. Similar Questions and Discussions

    1. How to secure database password? (was Perl/DBI newbie: password storage / security question)
      Zedgar, You are chasing the yourself into circles. Security is dictated by circumstances and resources available. In our case, we had plenty of...
    2. checking userid and password against windows domain (Active directory)
      hi. to prevent separate systems with different accounts, i am looking for a perl module that will allow me to check the userID (username) and...
    3. How to secure database password? (was Perl/DBI newbie: password storage / security question)
      Hello, Many thanks to R. Joseph Newton, Motherofperls, essential quint and Chuck Fox for answering my questions, however it is still not what I...
    4. How to secure database password? (was Perl/DBI newbie: password stora...
      The only solutions I've discovered is: ( for less secure tables) 1. Crypt the password 2. Put it into directory not in the public domain 3. Set...
    5. OT: What is the default password for MYSQL??
      Hi, This is off-topic... but I wanted to tinker with mysql.. Does anyone know the default password? It says username: root port: 3306 ...
  3. #2

    Default Re: Checking password with mysql & PASSWORD()

    On Sat, 14 Aug 2004 22:12:24 GMT, "John Victor" <wiegeabo@pacbell.net> wrote:
    >In my mysql database, I've stored all the passwords using the PASSWORD()
    >function. Now I'm running a test and need to compare the password in my php
    >document to that saved in the database. I used the string
    >
    >"Select name From users Where password = PASSWORD('$testPass')"
    >
    >and ran mysql_query() using the string. But nothing was returned.
    OK - what's in the table? What's in $testPass? Something must not match up...
    > So I
    >decided to run a test and try to change a password from my php page using
    >the string
    >
    >Update users Set password = PASSWORD('$newPass') Where name = 'userName1'"
    >
    >and it works fine. My database is updated properly. So my question is, why
    >can't I find a match using the PASSWORD function, but can still update my
    >table?
    There's no connection between the two queries, so why shouldn't you be able to
    update the table by the name field if the password field doesn't match your
    expectations?

    --
    Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
    <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
    Andy Hassall Guest

  4. #3

    Default Re: Checking password with mysql & PASSWORD()

    The fields, and variables, all just hold strings. The problem is that I'm
    unable to check the password someone has typed against the encrypted
    password in the table, yet I can somehow use the encrypted password to make
    changes to a table.




    --
    John


    "Andy Hassall" <andy@andyh.co.uk> wrote in message
    news:8i7th057kdovoguqqfbmt4suljtrssdvaq@4ax.com...
    > On Sat, 14 Aug 2004 22:12:24 GMT, "John Victor" <wiegeabo@pacbell.net>
    wrote:
    >
    > >In my mysql database, I've stored all the passwords using the PASSWORD()
    > >function. Now I'm running a test and need to compare the password in my
    php
    > >document to that saved in the database. I used the string
    > >
    > >"Select name From users Where password = PASSWORD('$testPass')"
    > >
    > >and ran mysql_query() using the string. But nothing was returned.
    >
    > OK - what's in the table? What's in $testPass? Something must not match
    up...
    >
    > > So I
    > >decided to run a test and try to change a password from my php page using
    > >the string
    > >
    > >Update users Set password = PASSWORD('$newPass') Where name =
    'userName1'"
    > >
    > >and it works fine. My database is updated properly. So my question is,
    why
    > >can't I find a match using the PASSWORD function, but can still update my
    > >table?
    >
    > There's no connection between the two queries, so why shouldn't you be
    able to
    > update the table by the name field if the password field doesn't match
    your
    > expectations?
    >
    > --
    > Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
    > <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool

    John Victor Guest

  5. #4

    Default Re: Checking password with mysql & PASSWORD()

    On Sun, 15 Aug 2004 04:34:20 GMT, "John Victor" <wiegeabo@pacbell.net> wrote:
    >>>In my mysql database, I've stored all the passwords using the PASSWORD()
    >>>function. Now I'm running a test and need to compare the password in my
    >>>php document to that saved in the database. I used the string
    >>>
    >>>"Select name From users Where password = PASSWORD('$testPass')"
    >>>
    >>>and ran mysql_query() using the string. But nothing was returned.
    >>
    >> OK - what's in the table? What's in $testPass? Something must not match
    >> up...
    >>
    >>> So I
    >>>decided to run a test and try to change a password from my php page using
    >>>the string
    >>>
    >>>Update users Set password = PASSWORD('$newPass') Where name =
    >>'userName1'"
    >>>
    >>>and it works fine. My database is updated properly. So my question is,
    >>>why
    >>>can't I find a match using the PASSWORD function, but can still update my
    >>>table?
    >>
    >> There's no connection between the two queries, so why shouldn't you be
    >> able to update the table by the name field if the password field doesn't match
    >> your expectations?
    >
    >The fields, and variables, all just hold strings. The problem is that I'm
    >unable to check the password someone has typed against the encrypted
    >password in the table,
    Which is why I asked for examples of the contents of the variables and the
    table...
    >yet I can somehow use the encrypted password to make
    >changes to a table.
    Where did you demonstrate this? Your second query simply matched on the name
    field, it didn't use the encrypted password anywhere in the WHERE clause.


    Somewhere in your code your password variables must be holding the wrong
    values, since the approach you are taking is certainly valid, e.g.:

    mysql> insert into users values ('andy', password('blah'));
    Query OK, 1 row affected (0.01 sec)

    mysql> select * from users where password = password('blah');
    +------+------------------+
    | name | password |
    +------+------------------+
    | andy | 652f9c175d1914f9 |
    +------+------------------+
    1 row in set (0.01 sec)

    --
    Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
    <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
    Andy Hassall Guest

  6. #5

    Default Re: Checking password with mysql & PASSWORD()

    > Somewhere in your code your password variables must be holding the wrong
    > values, since the approach you are taking is certainly valid, e.g.:
    >
    > mysql> insert into users values ('andy', password('blah'));
    > Query OK, 1 row affected (0.01 sec)
    >
    > mysql> select * from users where password = password('blah');
    > +------+------------------+
    > | name | password |
    > +------+------------------+
    > | andy | 652f9c175d1914f9 |
    > +------+------------------+
    > 1 row in set (0.01 sec)
    >
    > --
    > Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
    > <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool

    I've tried something a little different. For clarity I removed the
    variables. I was able to change a field using this statment:
    Update users Set name = 'John1' Where PASSWORD('userPass')

    But trying to select that field using the password function failed:
    Select name From users Where password = PASSWORD('userPass')

    Now, I've just noticed an error I made in the update query. It should say
    Where password = PASSWORD('userPass') but I left out password =. Funny
    thing is, when I fix the statement, it no longer works in my php page or as
    a query when running mysql from the shell.

    This is frying my brain.


    --
    John


    John Victor Guest

  7. #6

    Default Re: Checking password with mysql & PASSWORD()

    On Sun, 15 Aug 2004 18:19:04 GMT, "John Victor" <wiegeabo@pacbell.net> wrote:
    >> Somewhere in your code your password variables must be holding the wrong
    >> values, since the approach you are taking is certainly valid, e.g.:
    >>
    >> mysql> insert into users values ('andy', password('blah'));
    >> Query OK, 1 row affected (0.01 sec)
    >>
    >> mysql> select * from users where password = password('blah');
    >> +------+------------------+
    >> | name | password |
    >> +------+------------------+
    >> | andy | 652f9c175d1914f9 |
    >> +------+------------------+
    >> 1 row in set (0.01 sec)
    >
    >I've tried something a little different. For clarity I removed the
    >variables. I was able to change a field using this statment:
    >Update users Set name = 'John1' Where PASSWORD('userPass')
    Why are you changing the name for a user now, I thought you were trying to set
    the password?

    PASSWORD('userPass') is alway true, so you've now either:

    (a) Trashed your table - everyone will have name John1
    (b) Ignored an error - because that should have caused a key violation

    If (a) then your table's design is wrong, since you seem to be using name as a
    key value, so it should be set as a key in the table.

    If (b) you're making your life far more difficult than it need be if you're
    ignoring errors.
    >But trying to select that field using the password function failed:
    >Select name From users Where password = PASSWORD('userPass')
    You didn't set it to PASSWORD('userPass'), so again there's no demonstrated
    reason why it should return anything.
    >Now, I've just noticed an error I made in the update query. It should say
    >Where password = PASSWORD('userPass') but I left out password =.
    Ah ha.
    > Funny
    >thing is, when I fix the statement, it no longer works in my php page or as
    >a query when running mysql from the shell.
    "No longer works" in what way?
    Again, what's in your table? Show some examples of real data. Show some sample
    code. etc.

    --
    Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
    <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
    Andy Hassall Guest

  8. #7

    Default Re: Checking password with mysql & PASSWORD()

    On Sun, 15 Aug 2004 18:19:04 GMT, John Victor <wiegeabo@pacbell.net> wrote:
    >> Somewhere in your code your password variables must be holding the
    >> wrong
    >> values, since the approach you are taking is certainly valid, e.g.:
    >>
    >> mysql> insert into users values ('andy', password('blah'));
    >> Query OK, 1 row affected (0.01 sec)
    >>
    >> mysql> select * from users where password = password('blah');
    >> +------+------------------+
    >> | name | password |
    >> +------+------------------+
    >> | andy | 652f9c175d1914f9 |
    >> +------+------------------+
    >> 1 row in set (0.01 sec)
    >>
    >> --
    >> Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
    >> <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
    >
    >
    > I've tried something a little different. For clarity I removed the
    > variables. I was able to change a field using this statment:
    > Update users Set name = 'John1' Where PASSWORD('userPass')
    >
    > But trying to select that field using the password function failed:
    > Select name From users Where password = PASSWORD('userPass')
    >
    > Now, I've just noticed an error I made in the update query. It should
    > say
    > Where password = PASSWORD('userPass') but I left out password =. Funny
    > thing is, when I fix the statement, it no longer works in my php page or
    > as
    > a query when running mysql from the shell.
    >
    > This is frying my brain.
    I suggest that you convert password into a md5 hash and save the hash into
    database. When selecting, use md5($password) in query. Such as $query =
    "SELECT * FROM users WHERE password = '" . md5($password) . "'";

    --
    Jari Lehtinen
    [url]http://www.jarilehtinen.net[/url]
    Jari Lehtinen Guest

  9. #8

    Default Re: Checking password with mysql & PASSWORD()

    On Sun, 15 Aug 2004 21:42:42 +0300, Jari Lehtinen
    <jari@--no-spam--jarilehtinen.net> wrote:
    > On Sun, 15 Aug 2004 18:19:04 GMT, John Victor <wiegeabo@pacbell.net>
    > wrote:
    >
    >>> Somewhere in your code your password variables must be holding the
    >>> wrong
    >>> values, since the approach you are taking is certainly valid, e.g.:
    >>>
    >>> mysql> insert into users values ('andy', password('blah'));
    >>> Query OK, 1 row affected (0.01 sec)
    >>>
    >>> mysql> select * from users where password = password('blah');
    >>> +------+------------------+
    >>> | name | password |
    >>> +------+------------------+
    >>> | andy | 652f9c175d1914f9 |
    >>> +------+------------------+
    >>> 1 row in set (0.01 sec)
    >>>
    >>> --
    >>> Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
    >>> <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
    >>
    >>
    >> I've tried something a little different. For clarity I removed the
    >> variables. I was able to change a field using this statment:
    >> Update users Set name = 'John1' Where PASSWORD('userPass')
    >>
    >> But trying to select that field using the password function failed:
    >> Select name From users Where password = PASSWORD('userPass')
    >>
    >> Now, I've just noticed an error I made in the update query. It should
    >> say
    >> Where password = PASSWORD('userPass') but I left out password =. Funny
    >> thing is, when I fix the statement, it no longer works in my php page
    >> or as
    >> a query when running mysql from the shell.
    >>
    >> This is frying my brain.
    >
    > I suggest that you convert password into a md5 hash and save the hash
    > into database. When selecting, use md5($password) in query. Such as
    > $query = "SELECT * FROM users WHERE password = '" . md5($password) . "'";
    Forgot to mention. For improved security, add a extra string when hashing,
    such as:
    md5($password . '398th34ghf73fHG') so it'll be harder to crack.

    --
    Jari Lehtinen
    [url]http://www.jarilehtinen.net[/url]
    Jari Lehtinen Guest

  10. #9

    Default Re: Checking password with mysql & PASSWORD()

    The user table I'm testing right now is very simple. It only has two
    fields: name and password. Example values would be 'John' and '266a88fc2c'
    (which is the result of PASSWORD('pword101')).

    The two tasks I now want to accomplish in the test is to simply find a name
    using the PASSWORD() function, as well as find a name and change the
    password. (This is just testing, it doesn't have to make sense in the real
    world.)

    But neither of my queries are working:

    "Select name From users Where password = PASSWORD('pword101')"

    "Update users Set password = PASSWORD('pword202') Where name = 'John'"




    __________
    John


    John Victor Guest

  11. #10

    Default Re: Checking password with mysql & PASSWORD()

    On Mon, 16 Aug 2004 22:26:41 GMT, "John Victor" <wiegeabo@pacbell.net> wrote:
    >The user table I'm testing right now is very simple. It only has two
    >fields: name and password. Example values would be 'John' and '266a88fc2c'
    >(which is the result of PASSWORD('pword101')).
    At last some example data!

    '266a88fc2c' is not the result of PASSWORD('pword101').

    mysql> select password('pword101');
    +----------------------+
    | password('pword101') |
    +----------------------+
    | 266a88fc2c3cb949 |
    +----------------------+
    1 row in set (0.00 sec)

    This is on MySQL 4.0.18.

    Have you chosen a column type that it too short to contain the password value?
    >The two tasks I now want to accomplish in the test is to simply find a name
    >using the PASSWORD() function, as well as find a name and change the
    >password. (This is just testing, it doesn't have to make sense in the real
    >world.)
    >
    >But neither of my queries are working:
    >
    >"Select name From users Where password = PASSWORD('pword101')"
    >
    >"Update users Set password = PASSWORD('pword202') Where name = 'John'"
    In an earlier post I demonstrated that this approach does work, provided you
    use a long enough column.

    In any case, looking through the manual to find the length of string that
    PASSWORD produces finds the following warning:

    "Note: The PASSWORD() function is used by the authentication system in MySQL
    Server, you should not use it in your own applications. For that purpose, use
    MD5() or SHA1() instead. Also see RFC 2195 for more information about handling
    passwords and authentication securely in your application."

    So, see the manual for appropriate column lengths for either MD5 or SHA1.

    --
    Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
    <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
    Andy Hassall Guest

  12. #11

    Default Re: Checking password with mysql & PASSWORD()

    Thank you. That was the problem. My password field was too short. I
    thought I was doing the query correctly. I'm so glad it was just a simple
    database problem, and I wasn't losing my mind. And thanks for the PASSWORD
    note. I'm going to use either md5 or sha1 instead.


    John


    "Andy Hassall" <andy@andyh.co.uk> wrote in message
    news:5be2i0t0sckuo1a1uirq79e2tn5gt17ogc@4ax.com...
    > On Mon, 16 Aug 2004 22:26:41 GMT, "John Victor" <wiegeabo@pacbell.net>
    wrote:
    >
    > >The user table I'm testing right now is very simple. It only has two
    > >fields: name and password. Example values would be 'John' and
    '266a88fc2c'
    > >(which is the result of PASSWORD('pword101')).
    >
    > At last some example data!
    >
    > '266a88fc2c' is not the result of PASSWORD('pword101').
    >
    > mysql> select password('pword101');
    > +----------------------+
    > | password('pword101') |
    > +----------------------+
    > | 266a88fc2c3cb949 |
    > +----------------------+
    > 1 row in set (0.00 sec)
    >
    > This is on MySQL 4.0.18.
    >
    > Have you chosen a column type that it too short to contain the password
    value?
    >
    > >The two tasks I now want to accomplish in the test is to simply find a
    name
    > >using the PASSWORD() function, as well as find a name and change the
    > >password. (This is just testing, it doesn't have to make sense in the
    real
    > >world.)
    > >
    > >But neither of my queries are working:
    > >
    > >"Select name From users Where password = PASSWORD('pword101')"
    > >
    > >"Update users Set password = PASSWORD('pword202') Where name = 'John'"
    >
    > In an earlier post I demonstrated that this approach does work, provided
    you
    > use a long enough column.
    >
    > In any case, looking through the manual to find the length of string that
    > PASSWORD produces finds the following warning:
    >
    > "Note: The PASSWORD() function is used by the authentication system in
    MySQL
    > Server, you should not use it in your own applications. For that purpose,
    use
    > MD5() or SHA1() instead. Also see RFC 2195 for more information about
    handling
    > passwords and authentication securely in your application."
    >
    > So, see the manual for appropriate column lengths for either MD5 or SHA1.
    >
    > --
    > Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
    > <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
    >

    John Victor Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139