Professional Web Applications Themes

Problem with PASSWORD and ENCODE functions - MySQL

Hi I'm new to MySQL. I have installed MySQL v5.0.27 on Windows 2000 Professional for some practice. I created a table as follows: create table users (user_id int unsigned not null auto_increment, user_pass char(16), user_name tinyblob, primary key (user_id)); Then inserted some records using the following statement: insert into users values(null, password('password'), encode('myname', 'w1cket')); Finally I tried to retrieve one record as follows: select user_id from users where (user_pass = password('password')) and (decode(user_name, 'w1cket') = 'myname'); According to the book that I'm following, it should retrieve "user_id=1" but it's not responding at all. It's not even generating any errors. Please ...

  1. #1

    Default Problem with PASSWORD and ENCODE functions

    Hi

    I'm new to MySQL. I have installed MySQL v5.0.27 on Windows 2000
    Professional for some practice.

    I created a table as follows:

    create table users (user_id int unsigned not null auto_increment, user_pass
    char(16), user_name tinyblob, primary key (user_id));

    Then inserted some records using the following statement:

    insert into users values(null, password('password'), encode('myname',
    'w1cket'));

    Finally I tried to retrieve one record as follows:

    select user_id from users where (user_pass = password('password')) and
    (decode(user_name, 'w1cket') = 'myname');

    According to the book that I'm following, it should retrieve "user_id=1" but
    it's not responding at all. It's not even generating any errors.

    Please note that there are three records in the table, I have checked that
    using 'select' statement. Although user_pass and user_name records are
    encrypted but they are there.

    One noticeable fact is that the book was written when MySQL 3 and 4 were the
    latest versions now it's 5. Most probably syntax has changed or so I think.
    I tried exhaustively to search the answer on MySQL website and a few others
    but failed. Maybe some more experienced user here can help me out.

    Thanks in advance.

    KKien


    K Guest

  2. #2

    Default Re: Problem with PASSWORD and ENCODE functions

    "K Kien" <com> wrote:
     

    I's simply not finding a match. For good reason.

    First: throw away that book. It's pretty much outdated. You must never,
    NEVER EVER use the PASSWORD() function for your own password hashing
    purposes. The only reason for PASSWORD() being available, is to use it
    to update MySQLs own permission tables (however using GRANT is strongly
    suggested for that purpose).


    Now why does your query not get any results?

    Because the PASSWORD() function has changed. It now resturns 41
    characters (the corresponding column type would be char(41)).
    Thus it will never match the truncated 16 chars in your user_pass
    column. Also you should have got a warning about the truncation for
    the INSERT statement.


    XL
    --
    Axel Schwenke, Senior Software Developer, MySQL AB

    Online User Manual: http://dev.mysql.com/doc/refman/5.0/en/
    MySQL User Forums: http://forums.mysql.com/
    Axel Guest

  3. #3

    Default Re: Problem with PASSWORD and ENCODE functions

    Hi Axel

    Thanks a lot, it did work. Surprisingly, I did not get any warning about the
    truncation for the INSERT statement.

    Regards

    K Kien

    "Axel Schwenke" <de> wrote in message
    news:homelinux.org... [/ref]
    user_pass [/ref]
    but 
    >
    > I's simply not finding a match. For good reason.
    >
    > First: throw away that book. It's pretty much outdated. You must never,
    > NEVER EVER use the PASSWORD() function for your own password hashing
    > purposes. The only reason for PASSWORD() being available, is to use it
    > to update MySQLs own permission tables (however using GRANT is strongly
    > suggested for that purpose).
    >
    >
    > Now why does your query not get any results?
    >
    > Because the PASSWORD() function has changed. It now resturns 41
    > characters (the corresponding column type would be char(41)).
    > Thus it will never match the truncated 16 chars in your user_pass
    > column. Also you should have got a warning about the truncation for
    > the INSERT statement.
    >
    >
    > XL
    > --
    > Axel Schwenke, Senior Software Developer, MySQL AB
    >
    > Online User Manual: http://dev.mysql.com/doc/refman/5.0/en/
    > MySQL User Forums: http://forums.mysql.com/[/ref]


    K Guest

Similar Threads

  1. Problem to encode MPEG
    By ramaplus in forum Macromedia Flash Data Integration
    Replies: 0
    Last Post: December 12th, 05:36 PM
  2. Replies: 11
    Last Post: April 10th, 03:54 PM
  3. Encode::Arabic, Encode::Korean and Encode::Mapper
    By Otakar Smrz in forum PERL Modules
    Replies: 0
    Last Post: August 26th, 01:39 PM
  4. Strange problem...some functions just don't work.
    By Kim Bellomy in forum Adobe Photoshop 7, CS, CS2 & CS3
    Replies: 1
    Last Post: August 12th, 06:39 AM
  5. Encode or not to encode, that is the question
    By fartsniff in forum PHP Development
    Replies: 1
    Last Post: July 14th, 12:15 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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