<form action="verify.php" method="post">
<p><label for='username'>Username</label>
<input type='text' name='username' id='username'/>
</p>
<p><label for='password'>Password</label>
<input type='text' name='password' id='password'/>
</p>
<p><input type="submit" name="submit" value="log in"/>
</p>
</form>
|
<?php
$user = $_POST['user'];
$pw = $_POST['password'];
$sql = "select user,password from users
where user='$user'
and password='$pw'
limit 1';
$result = mysql_query($sql);
if (mysql_num_rows($result)){
//we have a match!
}else{
//no match
}
?>
|
<?php
$user = strip_tags(substr($_POST['user'],0,32));
$pw = strip_tags(substr($_POST['password'],0,32));
$sql = "select user,password from users
where user='". mysql_real_escape_string($user)."'
and password='". mysql_real_escape_string($pw)."'
limit 1';
$result = mysql_query($sql);
if (mysql_num_rows($result)){
//we have a match!
}else{
//no match
}
?>
|
<?php
$user = strip_tags(substr($_POST['user'],0,32));
$pw = strip_tags(substr($_POST['password'],0,32));
$cleanpw = crypt($pw);
$sql = "insert into users (username,password)
values('".mysql_real_escape_string($user)."',
'".mysql_real_escape_string($cleanpw)."')";
//.....etc....
?>
|
算法
|
Salt
|
CRYPT_STD_DES
|
2
个字符(默认)
|
CRYPT_EXT_DES
|
9
个字符
|
CRYPT_MD5
|
12
个字符,以
$1$
开头
|
CRYPT_BLOWFISH
|
16
个字符,以
$2$
开头
|
<?php
$user = strip_tags(substr($_POST['user'],0,32));
$pw = strip_tags(substr($_POST['password'],0,32));
$cleanpw = crypt(md5($pw),md5($user));
$sql = "insert into users (username,password)
values('".mysql_real_escape_string($user)."',
'".mysql_real_escape_string($cleanpw)."')";
//.....etc....
?>
|
<?php
$user = strip_tags(substr($_POST['user'],0,32));
$pw = strip_tags(substr($_POST['password'],0,32));
$cleanpw = crypt(md5($pw),md5($user));
$sql = "select user,password from users
where user='". mysql_real_escape_string($user)."'
and password='". mysql_real_escape_string($cleanpw)."'
limit 1';
$result = mysql_query($sql);
if (mysql_num_rows($result)){
//we have a match!
}else{
//no match
}
?>
|
<?php
$user = strip_tags(substr($_POST['user'],0,32));
$pw = strip_tags(substr($_POST['password'],0,32));
$cleanpw =crypt($pw, substr($user,0,2));
$sql = "select user,password from users
where user='". mysql_real_escape_string($user)."'
and password='". mysql_real_escape_string($cleanpw)."'
limit 1';
$result = mysql_query($sql);
if (mysql_num_rows($result)){
//we have a match!
}else{
//no match
}
?>
|
<?php
//set up users
$from = "[email protected]";
$to = "[email protected]";
//cut the message down to size, remove HTML tags
$messagebody = strip_tags(substr($_POST['msg'],0,5000));
$message_body = escapeshellarg($messagebody);
$gpg_path = '/usr/local/bin/gpg';
$home_dir = '/htdocs/www';
$user_env = 'web';
$cmd = "echo $message_body | HOME=$home_dir USER=$user_env $gpg_path" .
"--quiet --no-secmem-warning --encrypt --sign --armor " .
"--recipient $to --local-user $from";
$message_body = `$cmd`;
mail($to,'Message from Web Form', $message_body,"From:$from\r\n");
?>
|