Click here to Skip to main content
15,908,254 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have MySql database and want to encrypt the 'password' column of 'users' table, so that if any one enters to database it is not visible to him.I am trying to do it but could not succeed.
What i am doing in query is.
C#
insert into users(id,password) values('09678M',AES_ENCRYPT('secretkey'));

but it returns:The query could not be executed Where i am making mistakes.

Please guide me the correct syntax.

Thanks.
Posted
Updated 21-Nov-13 22:14pm
v2

In addition to Solution 1 and 2:

The hash function you use for password storage and authentication should be cryptographic hash function: http://en.wikipedia.org/wiki/Cryptographic_hash_function[^].

The implementations are readily available, come with .NET Framework FCL. Please see my past answers:
i already encrypt my password but when i log in it gives me an error. how can decrypte it[^],
Decryption of Encrypted Password[^],
storing password value int sql server with secure way[^],
TCP Connection with username and password[^].

—SA
 
Share this answer
 
Comments
Thanks7872 22-Nov-13 12:36pm    
Agreed.
Sergey Alexandrovich Kryukov 22-Nov-13 12:47pm    
Thank you, Rohan.
—SA
The way you are trying to implement this is wrong at first place. Never ever store password either in plain text or in encrypted format.

The correct way is to store hash of the password. That is,try using one way cryptographic hash function like SHA256 to generate hash from password,store it in database. You should also use salt.See this link : Beginners guide to a secure way of storing passwords[^]

Whenever user tries to login,generate hash from the entered password using the same algorithm and compare it with stored one. So now,your are comparing hash to hash,not password to password.
 
Share this answer
 
v4
Comments
[no name] 22-Nov-13 4:47am    
thanks for great suggestion.
does this code work for datatime datatype?
Thanks7872 22-Nov-13 4:50am    
Date time? Why?
[no name] 22-Nov-13 4:55am    
because i have a table application_validity(validity) and a record with deadline date.
during login it will be used to validate if current date of system exceds it user will not be able to login.
this is all for personal use regarding payment.
Thanks7872 22-Nov-13 5:00am    
No need to use this approach in case of date. Simply do it once user is verified successfully.
[no name] 22-Nov-13 5:04am    
ok sir, thank you.
XML
AES_ENCRYPT should be like
<pre>insert into users(id,password) values('09678M',AES_ENCRYPT('actualpassword','secretkeyusedtoencrytp'));</pre>


But Rohan is correct, sha256 is prob too fast hash algorithm but it is still better then AES or plain text.
 
Share this answer
 
Comments
[no name] 22-Nov-13 4:57am    
thanks for great suggestion.
but sir i want to know does this AES technique work for datatime datatype?
Hamassss 22-Nov-13 5:05am    
I think it only works on string, then some type conversions should be must, if that is the case
Sergey Alexandrovich Kryukov 22-Nov-13 11:27am    
You are right, but some clarifications would be needed.
I voted 4, added my answer to clarify things, please see.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900