473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to encrypt password in MySQL database?

170 100+
hi guys,
i would like to ask thing son encryption of data
presently i'm setting up a mysql database to store usernames and password for authentication

is there ways i can encrypt the column passwords even to the database administrator? i know of MD5 but how do i actually go about doing it?
May 12 '08 #1
5 41465
Atli
5,058 Expert 4TB
Hi.

There is a simple way to do that by using either the MD5 or SHA1 hashing functions. The essentially do the same thing, but the SHA1 function creates a longer hash, which makes it more secure.

Just do something like this:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO myUserTbl(UserName, Password) 
  2. VALUES('myUserName', SHA1('myPassword'));
  3.  
And then, when it comes to validating the password you can do something like:
Expand|Select|Wrap|Line Numbers
  1. SELECT UserID FROM myUserTbl 
  2. WHERE UserName = 'myUserName'
  3. AND Password = SHA1('myPassword');
  4.  
This way, nobody can read any of the passwords, not even with full access to your database.
May 12 '08 #2
poolboi
170 100+
Hi.

There is a simple way to do that by using either the MD5 or SHA1 hashing functions. The essentially do the same thing, but the SHA1 function creates a longer hash, which makes it more secure.

Just do something like this:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO myUserTbl(UserName, Password) 
  2. VALUES('myUserName', SHA1('myPassword'));
  3.  
And then, when it comes to validating the password you can do something like:
Expand|Select|Wrap|Line Numbers
  1. SELECT UserID FROM myUserTbl 
  2. WHERE UserName = 'myUserName'
  3. AND Password = SHA1('MyPassword');
  4.  
This way, nobody can read any of the passwords, not even with full access to your database.
hi,
hm..with respect to yr validation part
i realise when i printed this SQL statement on mysql client
it returns me an empty set
so i'm not sure if that really works
May 27 '08 #3
Atli
5,058 Expert 4TB
hi,
hm..with respect to yr validation part
i realise when i printed this SQL statement on mysql client
it returns me an empty set
so i'm not sure if that really works
It does work. I've used this method on several projects myself.

If you are using the exact code I posted tho, the problem may be that I misspelled the second password. It should start with a lowercase 'm'.

I've corrected the typo in my old post.
May 27 '08 #4
poolboi
170 100+
It does work. I've used this method on several projects myself.

If you are using the exact code I posted tho, the problem may be that I misspelled the second password. It should start with a lowercase 'm'.

I've corrected the typo in my old post.
opps alright i know the problem
i declare the my length for my password in my password field too short
that's why the verifying ran into problems
thanks anyway atli
May 28 '08 #5
sbmk
1
Thanks Atli, it really works.I have tried it.You're just GR8 !!!
Apr 24 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: mdh | last post by:
I am trying to learn the basics of MVC applications using a Tomcat infrastructure. I'm starting by building a simple application with: * a login.jsp page for a basic login form with a action...
2
by: mos | last post by:
I want to put a MySQL 4.1 database on a Win2k laptop but the problem is it contains confidential client information. It has to be Window because applications accessing the database are written in...
2
by: Daniel | last post by:
Hi All, Does anyone know how to encrypt the password before store in the sql database? In addition, decrypt the password from database before comparison. The purpose to do it because to hide the...
6
by: Bob Sanderson | last post by:
I have created a MySQL database for my company which is accessed by PHP pages. I would like to permit some users to edit the records but allow others read-only access. However, I don't want to have...
12
by: mistral | last post by:
phpMyAdmin 2.6.2 problem: can no connects to mySQL database: each time shown error #1045 - Access denied for user 'username'@'192.168.1.2' (using password: YES) Is seems, this is most common...
7
by: asenthil | last post by:
Hai to all, this is senthil... i'm now working in the field of VC++... i want to connect a mysql database... just now tried to retrieve rows from a simple mysql database by using VC++ My...
1
by: ghjk | last post by:
I m developing web base system. I want to add the facility to create users. And could you please tell me how to encrypt their password in mysql database?
39
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f...
4
by: Gary Baardman | last post by:
I am having a few problems returning records from a mySQL database using PHP. Firstly I must say I am trying to create a video album using MySQL, PHP and using pagination. My first problem is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.