Nov 22, 2009

Help In Storing Encrypted Passwords In MySQL

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Databases

Help In Storing Encrypted Passwords In MySQL

soleimanian
Hi,
I need some help with storing password in mysql database or something similar.
i used to store the password in database using md5() function but there is no way to retrieve thepassword back.

Now i want to know that -
is it standard and secure way to store password?
is there any other technique to store password so i can retrive it back?

Any advice on this would be highly appreciated.
you can my quwstion in other websites
Thanks

Comment/Reply (w/o sign-up)

miCRoSCoPiC^eaRthLinG
QUOTE(soleimanian @ Nov 17 2005, 03:45 PM)
Hi,
I need some help with storing password in mysql database or something similar.
i used to store the password in database using md5() function but there is no way to retrieve thepassword back.



- But that is the whole idea behind it - NOT TO BE ABLE TO decrypt passwords, the encryption process being just one-way. In almost any given scenario, you'll find the password being encrypted and stored the first time you enter it.

From next time onwards, whenever you login, the newly entered password is again encrypted - the matched against the stored & encrytped form in the database.

For security reasons password decryption routines are never built into the system. Why do you think, 99% of the web-based services (the more secure ones) never e-mail you your password, but instead ask you to set a new one when you forget your old one. SIMPLE - because your old password cannot be decrypted and mailed to you.

Having a decryption system in place (even if it is not accessible to outsiders) opens up the doorway for a prodigal system administrator or some lesser mortal in the same office, to have a means to decrypt the passwords of other users and have some fun with 'em wink.gif

Take for example - even on Linux, a sysadmin cannot KNOW or FIND OUT what a user's password is. In case it is lost or forgotten, at best he can reset it to something that the user desires.

QUOTE
Now i want to know that -
is it standard and secure way to store password?
is there any other technique to store password so i can retrive it back?


The standard technique (one-way) is the most secure you can get, although you can use some other routine and not just a simple MD5 hash.

If you're implementing this in your own application, you can easily use MySQL AES_ENCRYPT () function to store your passwords in an encrypted form (only constraint - the storage field in mysql has to be declared Binary).

AES_ENCRYPT (Advanced Encryption Standard), however has a matching decryption function too - AES_DECRYPT - with which you can achieve what you're seeking to do... but this just serves to weaken the security mechanism - like a weak-link in the chain.

Besides, to use either of these functions, you've to use a Secret Key - sort of a master password, which will be used to encrypt the stored passwords. You need to have this handy during decryption too..or else you can never get back the original pass.

One idea, in case you want to implement this method, is to generate this secret key dynamically for each user based on some other stored data, say their name/address/phone/date of birth etc.. so each user will have a separate secret key, with which you encrypt/decrypt their passwords.

Example:
Some stored fields in the database:
============================
  • UserID    [/tab][tab]--> Some Autoincrementing ID maybe
  • First_Name    [/tab] --> Joseph
  • Last_Name[tab]--> Somebody
  • Phone    [/tab][tab]--> 123456789
  • BirthDate    [/tab]--> 10/12/1900
  • Password[tab]--> mypassword
Once the user enters all the details (including a plain text password) in the web-form, I use a routine to:
  • Take the middle two characters of the First_Name = se
  • First and last character of Last_Name = Sy
  • Last 3 digits of Phone = 789
  • First two digits of birthdate = 10
I get my secret key = seSy78910

Now I use this to call the AES_ENCRYPT function and encrypt my password and put it in the password field in the DB along with another INSERT instruction to store the rest of the data:
CODE

INSERT INTO usertable ( First_Name, Last_Name, Phone, BirthDate ) VALUES ( '...', '...', '...', '......' );
UPDATE usertable SET Password = AES_ENCRYPT ( 'mypassword', 'seSy78910' ) WHERE UserID IN ( SELECT LAST_INSERT_ID FROM usertable );



There.. that statement should update the password field in your db with the encrypted form. By issuing these two statements together I can use the LAST_INSERT_ID to get the last inserted ID of the user (depends on the auto-incrementing field) and update the password.

OR,
You can issue both statements together in a single set of instructions, in this format:
CODE

INSERT INTO usertable ( First_Name, Last_Name, Phone, BirthDate, Password ) VALUES ( '...', '...', '...', '......', AES_ENCRYPT ( 'mypassword', 'seSy78910' ) );



Since the key to encrypt is being dynamically generated using some string manipulation routine, it'll always be unique for each user and quite secure in a sense. Only thing that you'll have to safeguard is this Key Generating Mechanism. If this falls into someone else's hands he can decrypt anybody's passwords in your db. So use some pretty ingenuous and complicated routine to generate this key.

Hope this will put you on the right track..

Regards,
m^e

 

 

 


Comment/Reply (w/o sign-up)

Quatrux
you can write your own encryption and decryption functions to encrypt/decrypt the passwords wink.gif but in my opinion the best is to use the way not to have a possibility to decrypt smile.gif

Comment/Reply (w/o sign-up)

curare
WOW, m^e, thank you for this explanation. It really sheds light on some questions I have been aksing for years.

Serious, man, this is the first time I *really* understand one-way versus two-way encryption. Someone famous said, the people which can expain complicated matters with simple words are the real geniuses.

I don't want to get into brown-nosing (remember, m^e, I used that term in my first post here 15 days ago), but this is an excellent example. Let me quote Albert Einstein, whom I admire among other things just for that, with another example: When asked how to explain the wireless telegraph, he responded, "The wireless telegraph is not difficult to understand. The ordinary telegraph is like a very long cat. You pull the tail in New York, and it meows in Los Angeles. The wireless is the same, only without the cat." biggrin.gif

Comment/Reply (w/o sign-up)

miCRoSCoPiC^eaRthLinG
Hahahaha thank you for that curare. That was simply a brilliant example. Thanks for the terrific new addition to my quotes & phrases handbook wink.gif

And since you brough the term brown-nosing up, I remember seeing an extremely hilarious rendition of it on Webster.Com..

QUOTE
Main Entry: brown·nose
Pronunciation: 'brau(n)-"nOz
Function: transitive verb
Etymology: from the implication that servility is equivalent to kissing the hinder parts of the person from whom advancement is sought

slang : to ingratiate oneself with : curry favor with
- brownnose noun
- brown·nos·er noun

Source: http://www.webster.com/cgi-bin/dictionary?va=brownnosing


What can I say except - "Very well put" wink.gif

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : storing, encrypted, passwords, mysql

  1. Login System
    I want to make a login system using Mysql. I am amateur in these thing (12)
  2. Mysql Overhead
    (3)
    Sometimes in a table especially if i do alot of things in it i start seeing overhead then a size
    near it? what is overhead? and is it essential to optimize the table to fix it? I know its just a
    press of a button but i'd like to know what happens when i optimize a table. Also when you make
    a new table you can limit the size of VARCHAR to a number, that number would be the number
    characters allowed in that column per entry. I'd like to know how the limit works for texts, is
    it in KB? or number of characters? Cuz i made a messaging system. And i remember reading s....
  3. Mysql Multiple Tables
    (3)
    It is good practice to use multiple tables to sort out big amounts of data. But once you do that it
    becomes increasingly hard to cross reference the tables. Mysql has a little beautiful command
    structure that they have added. You can select multiple tables within one sql query. Example of a
    basic sql query CODE $sql = "SELECT * FROM table WHERE row=1"; If you noticed that I selected
    all of the rows in the table. Normally you will try to not select the entire table from the database
    unless you absolutely want all of the table. I would recommend against it; just gra....
  4. Any Website Provide Free Host Mysql Host?
    (4)
    any website provide free host mysql host? i need it because i am using 000webhost.com now but it
    only provide 2 mysql database... can i know where or how can i get more databases regards....
  5. Mysql On Computer
    XD (9)
    I posted PHP on computer? , but for some reason it doesn't show :/. Anyways I am wondering if
    there is MYSQL on my computer, meaning can i make a data base on my computer? that way i make what i
    want and upload it when i get hosted =)....
  6. Mysql Database Entry By Excel Sheets
    (2)
    Hello .. I would like to ask if i can use use Microsoft excel files in order to make entries to
    mysql database. Thanks....
  7. Mysql Database Management
    (1)
    Hi i am new, I have a problem in understanding the query decomposition in D-DB. Can anyone help me
    to understand the first question of the exercise 25.21 of Elmasri-Navath 4th edition? Consider the
    following relations: BOOKS (Book#, Primary_author, Topic, Total_stock, $price) BOOKSTORE (Store#,
    City, State, Zip, Inventory_value) STOCK (Store#, Book#, Qty) Consider a distributed database for a
    bookstore chain called National Books with 3 sites called EAST, MIDDLE, and WEST. Consider that
    BOOKS are fragmented by $price amounts into: B1:BOOK1:up to $20. B2:BOOK2:from ....
  8. Mysql And User File_priv
    (0)
    HI, I've hit the grain while trying to import file to mysql database - I need to enable file
    permissions of the database user but this seems not possible with most of the hosting providers.
    The problem is to set file_priv of the database user to "Y" . This is done in the "user" table of
    the maintanance database named "mysql". cPanel doesn't allow this. Via the cPanel you can only
    allow privileges on table querries but you cannot grant host file privileges to the database user -
    which makes querries like: "LOAD DATA INFILE 'filename' INTO TABLE tablen....
  9. I Have An Error With My Mysql Connection
    mysql connection error (7)
    ok so here's my web page... http://lacrossems.t35.org/ it only lags cause its trying to
    connect to the my sql server...i followed this guide
    http://forum.ragezone.com/showthread.php?t=387249 and when i edit my config.php to my host and
    login info i always get the error cannot connect to the database here is my config.php if you can
    help me CODE $host = 'CENSORED';                // my host $host =
    'righto';       // my database username $host = 'CENSORED';   // my database
    password $host = 'odinms';       // my datab....
  10. Mysql Backup With Another Address?
    (4)
    I just got my site hacked!! (don't worry because it is not on astahost) Actually it is a
    wordpress blog. So I backed up my MySQL Databases with cpanel. Now when I get my hosting approved
    here at astahost, can I restore those backups? Is the change of the site address going to interfere
    with this? Is there anyway I can edit those databases to work with my new address? Please help me
    out here!....
  11. Sun Bought Mysql
    (6)
    SUN bought the swedish company MYSQL for much money, around 2million each worker got in the company,
    they did it to come in to the database market, is it a good reson to buy it?....
  12. Mysql - So Hard
    Come in here if you think MySQL is soo hard! (14)
    Doesn't anybody think MySQL is so hard to code? I mean think about it, you need loads of
    databases just for one little script and you have to type things in like ;Host-Username:
    (blahblah) ;Host-Password: (blahblah) ;Host-DatabaseName: (blahblah) Ok, that MySQL code was
    random, and it is alot harder than that. If you have expierenced it being hard, you are free to
    post right in here, mate.....
  13. Login System Using A Mysql Db
    How do i do this? (5)
    Hi guys, ive got a registration system that looks something like the one below: Firstname:
    Lastname: Then i have inset.php, which looks like the following: $con =
    mysql_connect("localhost","autobot","abc123"); if (!$con) { die('Could not connect: ' .
    mysql_error()); }mysql_select_db("my_db", $con);$sql="INSERT INTO person (username, password) VALUES
    ('$_POST ','$_POST ')";if (!mysql_query($sql,$con)) { die('Error: ' .
    mysql_error()); } echo "1 record added";mysql_close($con) ?> Now my question is, how do i creat....
  14. Mysql And Php
    When trying to install Joomla (16)
    I don't know if this is the correct forum, but here is my question: I'm trying to test
    Joomla and some forums in my computer, I have already installed MySQL with the GUI tools, Apache,
    and PHP with the MySQL and MySQLi extensions, but when I'm trying to install Joomla I get this
    error: Required Settings Check: ------------------------------------- PHP version >= 4.1.0
    Yes - zlib compression support Available - XML support Available - MySQL support
    Unavailable configuration.php Writeable Session save path Unwriteable Not ....
  15. Permission Problem With Mysql Database Creation
    Please Help! (8)
    I seem to have a problem with accessing my database with proper permissions. I have set the my
    database correctly giving my db username all priviliges yet i seem to be unable to even log on with
    this username with a denied access error. Any ideas on resolving this?....
  16. Navcat For MySQL
    is Navcat any good? (9)
    Hello all, i ve recently come across NavCat (GUI tool) for MySQL. I have not bought a copy yet, just
    played around with the demo. Has any one used it beore, if so please let me know if its worth
    buying. I already have PhpMyadmin, Just wanna know if NavCat is better than PhpMyAdmin in usibility
    and functionality. Regards....
  17. Is It A Good Practice To Store Image Or Other Binary Files Directly In A Mysql Database
    (6)
    Hello to all of you beautifull people out there, I am new to MySQL, i just wanted to know if its a
    good practice to directly store images and other binary files in a MySQL database. Any one with
    help? Thanks....
  18. MySQL, Multiple Tables
    (27)
    Ok, I'm coding a project which is a leap than what I'd normally do. Before, I've always
    learned ONE table... put EVERYTHING in one database table. I'm making a profile system so there
    needs to be at least two tables: 1 for users, 1 for content. My problem is, how do I link the two
    together? I could probably figure this out faster if someone explained and posted sample SQL code
    that shows how the two are linked together. Thanks!! F....
  19. MySQL Output Database Question
    (19)
    I am new to MySql and have just created a database after using a script. My problem is not the
    script, but what it says about putting it into the output file. I cant figure out the right terms
    to put it in, I keep getting errors. I try using; SELECT*FROM 'database name' WHERE
    'location' but it isnt working. I'm lost with this stuff, I really am. Can someone
    please help me out?....
  20. MS-database To MySQL
    I'd like to batch them (6)
    Hi, maybe one of you already came across this, so I ask. I'll continue searching on. I've
    got two vocable trainers, one is Windows-native, the other one is on the web. While I can't
    control the output of the Windows-thing (so I can't export them to a *csv or something), I can
    write an import script. But since I'm not that great with Regular Expressions and don't know
    anything about *.mdb (that is MS SQL, isn't it?) files, I would need some finished thing to make
    out the field information and put it in arrays or something more readable. It wou....
  21. What Are The Alternatives To MySQL
    (7)
    Hi. i'm interested in alternatives to MySql combined with php. what database else can i use to
    create a webbased managment system with a lot of entries. maybe more than mysql can handle fast
    enough. it should be more powerful than mysql and should have nearly the same features. i hope
    there is a webbased administration program like phpmysqladmin thanks for your help ! greetings c.....
  22. How To Connect MySQL With Flash?
    Help me connect my flash Work with MySql (8)
    I know Flash and mysql but could not figure out if I could ever connect these? I want to have a
    dynamic content in my flash object that could be retrieved from the database directly without myself
    needing to update it again and again. How can I achieve this ? Do I have to install any additional
    controls or connectors to do that ? If yes any one tell me....
  23. Mirror My MySQL Database To Another Mysql Server
    (7)
    Hi..I want to ask if its possible to automatically mirror my mysql databases into another mysql
    server?or create a small php script to do this? The reason is because, we all know that database is
    very improtant if we have dynamic website. I have my forum hosted and i want to automatically
    mirror this or backup into another mysql server(free). Like in freesql.org. So that im not afraid
    that i forgot to backup my database..also i have one central backup database. Thanks for the
    help..Im looking forward for this posibility.....
  24. Recover Tables From A MySQL .frm File
    (9)
    I have a couple of .frm files with no corresponding data or index files. Is it possible to recover
    the table structure (field names, types, sizes, rows,col, etc) from these files? The table type is
    innodb....
  25. MySQL Database Problems
    (8)
    My friends have a little forum running here . The problem is that quite often we get the following
    message when we try to open the page: QUOTE Warning: mysql_connect(): Can't connect to
    local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in
    /home/vhosts/rohit.bizhat.com/forums/db/mysql4.php on line 48 Warning: mysql_error(): supplied
    argument is not a valid MySQL-Link resource in /home/vhosts/rohit.bizhat.com/forums/db/mysql4.php on
    line 330 Warning: mysql_errno(): supplied argument is not a valid MySQL-Link resource in
    /home/vhosts/roh....
  26. Error In Installing MySQL Server
    MySQL server cannot be started (9)
    I try to upgrade my MySQL server from 4.018 to 4.1.10a. Firstly, I downloaded mysql-4.1.10a (not the
    essential one) for win XP Then I install the new version after the old version was uninstalled.
    After the installation process, Instance Configurator comes up to help for the configuration. But an
    error occured when it try to start the MySQL service. Error messageis "cannot create windows
    service for MySQL. Error:0" So my MySQL server cannot be started. It is running win XP on my
    computer. Does anybody can tell me what is wrong?. Thanks (sorry for my bad english)....
  27. How Can I Import Csv Files To My MySQL Database?
    I was able to export but where's import? (3)
    I am having hard times finding that import csv in the mysql phpmyadmin. I once worked on some csv
    files and someone imported it on the mysql server. I was not able to ask him. Does someone know how
    can I import csv files in mysql server?....
  28. MySQL Datetime --> VB.NET Datetime Conversion Prob
    Any solutions ?? (4)
    Hi, Can anyone provide me with a quick example of fetching a MySQL Datetime Field and converting it
    into native VB.NET DateTime format ?? Say for example my db contains a couple of fields: Field1,
    Field2, DateField... one of which is the default MySQL DateTime. Say I'm using the following
    code to connect... CODE ConnectionString = "....." QueryString = "SELECT * FROM SomeTable" Dim
    myConnection As New MySql.Data.MySqlClient.MySqlConnection(ConnectionString) Dim myCommand As New
    MySql.Data.MySqlClient.MySqlCommand(QueryString, myConnection) Dim myReader As MySq....
  29. MySQL Realtime Replication
    how to replicate mysql in realtime (4)
    i dont know if this might be useful to ppl here, but this is a very good knowledge for serious
    siteadmins. while i was digging for mysql backup techniques, i've found that mysql is able to
    do realtime replication. the idea is that there are master server and slave server. both are having
    the same version of mysql installed. the data flows; Master >copy> Slave ( in realtime!)
    you'll never have to manually copy the database file of wasting your time to manually use the
    mysqldump command. here are the links; http://dev.mysql.com/doc/mysql/en/Replication_HOWTO.h....
  30. MySQL - Trouble With Bulk Insert Statements
    (3)
    I'm trying to insert about 500 rows into mysql, but I keep getting errors. If I copy and paste
    too many (about 50) insert statements at a time I get errors sometimes. I sometimes even get errors
    but then the row is skipped so I don't know there was an error (I'm using linux and SSH).
    What's the best way to get my insert statements to put the data in MySQL? Is there anyway that I
    can have it tell me if there where any errors all the statements are executed? Thanks for your
    help.....

    1. Looking for storing, encrypted, passwords, mysql

See Also,

*SIMILAR VIDEOS*
Searching Video's for storing, encrypted, passwords, mysql
advertisement



Help In Storing Encrypted Passwords In MySQL

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com