首页 > Apache, PHP > PHP 生成 .htpasswd 文件的用户名和密码

PHP 生成 .htpasswd 文件的用户名和密码

<?php

// – – – – – – – – – – – – – – – – – – –
// Author: Christopher Hair
// Website: http://www.chrishair.co.uk
// – – – – – – – – – – – – – – – – – – –

if (isset($_POST[‘submit’])){
$error = ”;
$username = trim(stripslashes($_POST[‘username’]));
$password = trim(stripslashes($_POST[‘password’]));

if ($username == ” || preg_match(‘/\s/m’, $username)) {
$error .= “<p><strong>Invalid Username.</strong></p>\n”;
}

if ($password == ” || preg_match(‘/\s/m’, $password)) {
$error .= “<p><strong>Invalid Password.</strong></p>\n”;
}

if ($error == ”) {
echo “<p>Success</p>\n”;
echo “<h1>” . htmlspecialchars($username) . “:” . crypt($password) . “</h1>\n”;
} else {
echo $error;
}
}

?>

分类:Apache, PHP 标签:,
  1. 还没有评论。
  1. No trackbacks yet.

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: