boa通过cookie验证管理员密码

写一个输入密码的网页 check.html  主要部分就是

 </div>
	<div class="content">
	<h3><font color ="gray">请输入管理员密码</h3>
	<div><input name="password" type="password" /></div>
	</br>
	<div><input type="button"  value="确定" οnclick="loadconfig()"/></div>
</div>
loadconfig()函数

  function loadconfig()
	{
		var code = 1009;
		netconfigfrm.actioncode.value = code;
		netconfigfrm.submit();
	}
此网页的功能就是将密码传给服务器,供cgi程序处理;

CGI部分

CGI处理密码的函数是:

static void set_cookie(){
	char password[32]={0};
	cgiFormString("password",password,32);
	if(strcmp(password,"123456")==0) //比较密码  
	{
	htmlHeader("The temp page");
	htmlBody();
	fprintf(cgiOut,"<SCRIPT LANGUAGE='JavaScript'>");
	fprintf(cgiOut, "parent.document.cookie = 'password=123456';");//123456就是密码 cookie的有效时间为直到浏览器关闭
	fprintf(cgiOut, "parent.window.location.href ='../index.html';");//cookie设置成功后跳转到index.html 这里前面加了一个../ ,是因为此时是在虚拟目录
	fprintf(cgiOut,"</SCRIPT>");		// ./cgi-bin下  如果直接写index.html 那么URL地址就是 http://ip地址/cgi-bin/index.html 那么就会报错,							//	http://ip地址/index.html 才是希望得到的
	htmlFooter();
	}
	else
	{
	htmlHeader("The temp page");
	htmlBody();
	fprintf(cgiOut,"<SCRIPT LANGUAGE='JavaScript'>");
	fprintf(cgiOut, "alert('密码错误')");
	fprintf(cgiOut,"</SCRIPT>");
	htmlFooter();
	}

}

在其他网页上的JavaScript加上以下两个函数:

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return ""
}

function checkCookie()
{
username=getCookie('password')
if (username!=null && username!="")
  return 0;
else 
  window.location.href="check.html"
}
在<body>你认为合适的 地方 (一般是最开始的地方)加上以下代码:

<SCRIPT LANGUAGE="JavaScript">
	checkCookie();
</SCRIPT>
检查是否设置了cookie,若没有设置就转到check.html,若设置了(即验证过密码了)就return 0.


当然 这里的密码没有经过加密处理,,有心人可能通过抓包得到密码,可以在脚本处设置加密步骤

希望可以帮助到大家

 PS:在这之前想用boa的验证用户功能 ,对比boa-0.93.16,修改boa-0.94.14rc21里面的源代码,使得boa-0.94.14rc21版能够实现验证用户,但是一直没有成功,每次启动boa服务器的使用,报错 can't recognise keyword “Auth”;  显然还是没有处理配置文件新加的 关键字 Auth 不知道有木有同志成功,望交流。。-^-


  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值