你好,我探索,当有人试图写密码字段php句柄中的空间作为喋喋不休,所以我怎么可以防止它。恳求我想如果尝试写空间得到消息说,不要试图写空间如何我可以从PHP的空间安全的HTML密码标签?
-1
A
回答
5
if (strpos($_POST['password'], ' ') !== false) {
echo "Don't try to write space.";
}
0
这将做的工作:
if (strpos($_POST['password'], ' ') !== false) {
echo "Don't try to write space.";
}
不过...。那泰(看上面),得到arguement是一个好的。 您不应限制用户在其密码中使用空格和其他字符。
$upass = $_POST['password'];
$usalt = substr(md5(uniqid(rand(), true)),0,7);
$upasshash = sha1(md5($upass).$usalt);
现在将用户信息存储在数据库中。 为了安全起见,请清理$ _POST ['用户名']。 同样使用修剪来清理不必要空间的字段。
$upass = trim($_POST['password']);
$uname = mysql_real_escape_string(trim($_POST['username']));
//Get the from data.
$usalt = substr(md5(uniqid(rand(), true)),0,7);
$upasshash = sha1(md5($upass).$usalt);
//Salt for extra security (prevent attackers from using rainbow tables)
$sql = " INSERT INTO users (uname, upasshash, usalt)
VALUES ('$uname', '$upasshash', '$usalt');";
mysql_query($sql);
一个好处是,你不会在密码字段的数据库中创建开销。 $upasshash
长度为40个字符。
更新: 这是一种登录用户的方式。
$mysqlcon = dbconnect();
$sql = "SELECT * FROM users WHERE uname = '$unamein';";
$result = mysql_query($sql);
if(mysql_num_rows($result) == 1){ //Does the user exists and is it only 1 user?
//Yes 1 match exacly
$fetch = mysql_fetch_assoc($result);
if(sha1(md5($upassin).$fetch['usalt']) == $fetch['upasshash']){ //Are the password hashes equal?
//Yes the hashes are equal
$_SESSION['check'] = true;
$_SESSION['uid'] = $fetch['uid'];
$_SESSION['uname'] = $fetch['uname'];
$message = 'Login succeded!';
}else{
//NO the hashes ar not equal
$message = 'Wrong password and/or username.';
}
mysql_close($mysqlcon);
}else{
// USER doest exist.
$message = 'Wrong password and/or username.';
}
出于安全原因,请不要告诉他们他们错误填写了哪个字段。
0
您还可以在JavaScript中添加支票以提高用户体验(比服务器往返时间更快的响应时间)。如果你使用这条路线,不要完全依赖它,因为用户可能禁用了JavaScript,并且还在PHP中添加了一个检查。
<html>
<head>
<title>JavaScript Form Validation</title>
<script type='text/javascript'>
function validate() {
var pass = document.myForm.passwd.value;
for (var i = 0; i < pass.length; i++) {
if (pass.charAt(i) == ' ') {
alert("Please don't use spaces in the password");
document.myForm.login.disabled = true;
return;
}
}
document.myForm.login.disabled = false;
}
</script>
</head>
<body>
<form method='post' name='myForm'>
<input type='password' name='passwd' id='passwd' onblur='validate()'/>
<input type='submit' name='login' id='login'/>
</form>
</body>
</html>
相关问题
- 1. 从HTML中安全地获取密码
- 2. 为安全性编码PHP标签?
- 3. Django的:允许安全的HTML标签
- 4. 我怎么能写PHP标签之间的html代码
- 5. 垂直间距的Wordpress HTML编码标准(HTML标签之间的空白)?
- 6. 如何检索密码以便以后可以安全地从内存中删除密码?
- 7. PHP安全登录 - 密码加密
- 8. 我可以安全地分发哈希密码吗?
- 9. 如何编写密码安全的类?
- 10. 空的HTML标签
- 11. 密码生成无安全编码的URL安全密文
- 12. 如何安全地输出包含HTML标签的内容?
- 13. 我如何HTML编码可能有html标签的文本,而不使用Javascript编码标签本身
- 14. 如何生成0到1之间的密码安全Double?
- 15. 如何存储密码以解密安全数据?
- 16. 忘记我的密码以保护数据库的安全
- 17. 标签之间的PHP全局变量
- 18. 我可以用cqlengine做'描述密码空间'吗?
- 19. 如何preg_match php html标签?
- 20. 是否可以在ASP标签之间添加HTML标签?
- 21. 的.htaccess安全VS密码
- 22. 相册的密码安全
- 23. MySQL的密码安全
- 24. 如何使我的密码输入密码重置功能安全?
- 25. 可以安全地存储其他网站的密码吗?
- 26. 如何在R中从ggplot2添加barplot中的空间以便我可以读取标签?
- 27. 我可以将标签中的HTML代码显示在我的页面中吗?
- 28. PHP标签之前的空间
- 29. 如何安全地存储我的CouchDB管理员密码?
- 30. PHP用户名/密码安全
为什么要防止密码中的空格字符? – 2011-01-23 12:56:45