密码标签html,如何我可以从PHP的空间安全的HTML密码标签?

这将做的工作:

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.';

}

出于安全原因,请不要告诉他们他们错误填写了哪个字段。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值