由于演示程序,所以有以下问题:
1,密码是明码传输。
本文在 C#建立最简单的web服务,无需IIS 的基础上完成。
具体步骤:
一,RequestProcessor增加变量mLogin,改写ParseRequestAndProcess函数。
protected bool mLogin = false;
public bool ParseRequestAndProcess(string[] RequestLines)//解析内容
{
char[] sp = new Char[1] { ' ' };
string[] strs = RequestLines[0].Split(sp);
if (strs[0] == "GET")
{
Send(strs[1], 0, 0);
}
else if ("POST" == strs[0])
{
for (int j = 1; j < RequestLines.Length; j++)
{
if (RequestLines[j].IndexOf('&') >= 0)
{
if( mLogin )
{
SendHeadrAndStr("已经登录,不能重复登录。");
}
else
{
//分拆用户名和密码
String sName = "";
String sPassWord = "";
string[] s = RequestLines[j].Split('&');
for (int k = 0; k < s.Length; k++)
{
string[] sItems = s[k].Split('=');
if (null == sItems || sItems.Length < 2)
continue;
if ("username" == sItems[0])
sName = sItems[1];
if ("password" == sItems[0])
sPassWord = sItems[1];
}
//模拟登录
if ("a" == sName && "b" == sPassWord)
{
mLogin = true;
SendHeadrAndStr("登录成功。");
}
else
{
SendHeadrAndStr("用户名、密码不匹配。");
}
}
}
}
}
return false;
}
二,改写index.htm。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>3</title>
<script>
function check()
{
var username=document.getElementById("username");
var pass=document.getElementById("password");
if(username.value=="")
{
alert("请输入用户名");
username.focus();
return false;
}
if(pass.value=="")
{
alert("请输入密码");
pass.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form name= "LoginForm" method="post" οnsubmit="return check()">
<table width="350" bgcolor="#ccffcc" style="border-color" border="1">
<tr>
<td width="100">
用户名
</td>
<td>
<input type="text" name="username" id="username">
</td>
</tr>
<tr>
<td>
密 码
</td>
<td>
<input type="password" name="password" id="password">
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type="submit" value="登 录" >
</td>
</tr>
</table>
</form>
</body>
</html>
2021年目标:完成新书《闻缺陷则喜》,本博客右上公告有下载、阅读链接。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~