Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
414 views
in Technique[技术] by (71.8m points)

php - Should I mysql_real_escape_string the password entered in the registration form?

When a user registers I clean the password with mysql_real_escape_string as follow

$password = clean($_POST['password']); 

Before adding it into database I use :

$hashedpassword = sha1('abcdef'.$password);

and save it into mySQL.

My question is should I clean it or am I protected that the password is hashed before adding it into the DB ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Well, there is one major misunderstanding.

mysql_real_escape_string() does not clean anything. It has nothing to do with security at all.

This function is used just to escape delimiters and nothing more. It can help you to put string data into SQL query - that's all.

So, every string you're going to put into query (by putting it in quotes), you have to prepare it with this function. In all other cases it would be useless or even harmful.

Thus,
out of this misunderstanding, you're doing 2 major mistakes here:

  • you're using this function not with data that's actually going to the query
  • you can spoil your password by adding some symbols to it, so, it become unusable

Also, as a side note, please bear in mind that this function should be always used in conjunction with mysql_set_charset, or otherwise a "_real_" part of this function become useless


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...