sql - Simple encryption technique for MySQL using PHP -


How can I encrypt a user password?

Please understand from the beginning. I already have this sample code:

  $ password = "john856"; $ Encrypt_password = MD5 ($ password); Echo $ encrypt_password;  

How do I include it in my existing code, which does not do any encryption?

  & lt; Php $ con = mysql_connect ("localhost", "root", ""); If (! $ Con) {dead ('Could not connect:' Mysql_error ()); } Mysql_select_db ("Coro", $ Conn); $ Sql ​​= "Username (name, FNAME, MNAME, UNAME, PW) value ('$ _POST [Lneym]', '$ _POST [Fneym]', '$ _POST [Mneym]', '$ _POST [unm ] ',' $ _POST [pass] ') "; If (! Mysql_query ($ sql, $ con)) {dead ('error:' mysql_error ()); } Echo "& lt; script> warnings ('user added! You can now use the system.') "; MySql_close ($ Conn)? & Gt;  

Let me start with another important point:

Never enter $ 1 _POST variables directly into the query, this makes you very weak.

You should walk at least on each form value, including:

  $ Lneym = $ _POST ["lunem"]; $ Lneym_halfway_safe = mysql_real_escape_string ($ Lneym); ... $ sql = "Include values ​​in the user (name, FNAME, MNAME, UNAME, PW) ('$ Lneym_halfway_safe',  

You can still include md5 () directly Can be removed:

$ PW = md5 ($ _ POST ["PW"]); // no escape_ string () is not required here, // md5 checksum is protected

and then enter '$ PW' for the password area.

The best part is that the database will be used as a class, its parametric Queries automatically run SQL Inject May help you in preventing the problem. Maybe you help.

Seeing that you are not able to add md5 () to your code (no personal criticism, we all Once it started there) I recommend you to read that copying the important security features of a web platform on the fundamentals of programming is extremely dangerous and it is likely to end in tears.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -