登录界面代码:
<div class="login">
<div class="login01"><div class="loginbd">
用户名:<input type="text" name="txtname" id="txtname" />
</div>
<div class="loginbd">
密 码:<input type="password" id="txtpwd" name="txtpwd" /></div>
<div class="loginbd">
验证码:<input type="text" id="txtyzm" name="txtyzm" size="6" />
<label class="img">
<img alt="" src="admin/checkcode.aspx" id="getcode_img" title="看不清请点击!" />
</label>
点击图片更换</div>
<div class="loginbd">
<input type="button" name="Viplogin" id="Viplogin" value="" οnclick="checkLogin();" />
<a href="FindPwdFirst.aspx">忘记密码</a></div>
<span id="msg_tip" style="color: Red"></span>
<div class="loginbd01">
还没注册?<a target="_blank" href="Register.aspx">快速注册</a></div>
</div>
</div>
脚本代码:
function checkLogin() {
var name = $("#txtname");
var pwd = $("#txtpwd");
var yzm = $("#txtyzm");
if (name.val() == "") {
alert("请输入用户名!");
name.focus();
return false
}
if (pwd.val() == "") {
alert("请输入密码!");
pwd.focus();
return false;
}
if (yzm.val() == "") {
alert("验证码不能为空!");
yzm.focus();
return false;
}
$.ajax({
type: "get",
url: "CheckLogin.aspx?paramName=" + escape(name.val()) + "¶mPwd=" + pwd.val() + "&checkcode=" + yzm.val(),
eache: false,
success: function (reg) {
var arr = reg.split('|');
var returnval = arr[0].toString();
if (returnval == "1 ") {
$("#msg_tip").text("URL解析错误");
document.getElementById("txtyzm").value = "";
$("#txtyzm").focus();
ShowValidImage();
return false;
}
if (returnval == "15") {
$("#msg_tip").text("验证码输入错误,请重新填写");
document.getElementById("txtyzm").value = "";
$("#txtyzm").focus();
ShowValidImage();
return false;
}
if (returnval == "8") {
$("#msg_tip").text("您输入的账号不存在");
document.getElementById("txtyzm").value = "";
$("#txtname").focus();
ShowValidImage();
return false;
}
if (returnval == "21") {
$("#msg_tip").text("您输入的账号未通过管理员审核");
document.getElementById("txtyzm").value = "";
$("#txtname").focus();
ShowValidImage();
return false;
}
else if (returnval == "9") {
$("#msg_tip").text("您输入的密码有误");
document.getElementById("txtname").select();
document.getElementById("txtyzm").value = "";
ShowValidImage();
return false;
}
else if (returnval == "10") {
$("#msg_tip").text("");
window.location.href = "Person.aspx";
}
}
});
}
$(document).ready(function () {
$("#getcode_img").click(ShowValidImage);
});
//更换验证码
function ShowValidImage() {
var numkey = Math.random() + (new Date().getDate());
document.getElementById("getcode_img").src = "admin/checkcode.aspx?NumKey=" + numkey;
}
var name = $("#txtname");
var pwd = $("#txtpwd");
var yzm = $("#txtyzm");
if (name.val() == "") {
alert("请输入用户名!");
name.focus();
return false
}
if (pwd.val() == "") {
alert("请输入密码!");
pwd.focus();
return false;
}
if (yzm.val() == "") {
alert("验证码不能为空!");
yzm.focus();
return false;
}
$.ajax({
type: "get",
url: "CheckLogin.aspx?paramName=" + escape(name.val()) + "¶mPwd=" + pwd.val() + "&checkcode=" + yzm.val(),
eache: false,
success: function (reg) {
var arr = reg.split('|');
var returnval = arr[0].toString();
if (returnval == "1 ") {
$("#msg_tip").text("URL解析错误");
document.getElementById("txtyzm").value = "";
$("#txtyzm").focus();
ShowValidImage();
return false;
}
if (returnval == "15") {
$("#msg_tip").text("验证码输入错误,请重新填写");
document.getElementById("txtyzm").value = "";
$("#txtyzm").focus();
ShowValidImage();
return false;
}
if (returnval == "8") {
$("#msg_tip").text("您输入的账号不存在");
document.getElementById("txtyzm").value = "";
$("#txtname").focus();
ShowValidImage();
return false;
}
if (returnval == "21") {
$("#msg_tip").text("您输入的账号未通过管理员审核");
document.getElementById("txtyzm").value = "";
$("#txtname").focus();
ShowValidImage();
return false;
}
else if (returnval == "9") {
$("#msg_tip").text("您输入的密码有误");
document.getElementById("txtname").select();
document.getElementById("txtyzm").value = "";
ShowValidImage();
return false;
}
else if (returnval == "10") {
$("#msg_tip").text("");
window.location.href = "Person.aspx";
}
}
});
}
$(document).ready(function () {
$("#getcode_img").click(ShowValidImage);
});
//更换验证码
function ShowValidImage() {
var numkey = Math.random() + (new Date().getDate());
document.getElementById("getcode_img").src = "admin/checkcode.aspx?NumKey=" + numkey;
}
CheckLogin.aspx.cs代码:
private void LoginChecking()
{
string checkCode = StringHelp.FilterSpeStr(Request.QueryString["checkcode"]);
if (string.IsNullOrEmpty(checkCode))
{
//验证码丢失
return;
}
//比较验证码是否正确,不区分大小写
if (string.Compare(checkCode, Session["LVNum"].ToString(), true) == 0)
{
string name = Request.QueryString["paramName"];
string pwd = Request.QueryString["paramPwd"];
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(pwd))
{
//错误1:URL解析错误
Response.Write("1|" + sysParam.ErrorPageTip("1"));
}
else
{
DataSet ds = BLL.web_vipuser.GetVip(name);
//用户是否存在
if (Validator.CheckDS(ds, 0))
{
string vipPwd = Tools.Encryption.MD5Encrypt(pwd);
//密码是否正确
if (ds.Tables[0].Rows[0]["password"].ToString() == vipPwd)
{
string state = ds.Tables[0].Rows[0]["state"].ToString();
//账号状态: 1正常 0 未审核
if (state == "0")
{
//此账号未通过管理员审核
Response.Write("21|" + sysParam.ErrorPageTip("21"));
}
else
{
// SetUserCookie(ds.Tables[0]);
Session["VipName"] = ds.Tables[0].Rows[0]["username"];
//登陆成功
Response.Write("10|" + sysParam.ErrorPageTip("10"));
Session.Timeout = 30;
}
}
else
{
//错误9:您输入的密码有误
Response.Write("9|" + sysParam.ErrorPageTip("9"));
}
}
else
{
//错误8:您输入的账号不存在
Response.Write("8|" + sysParam.ErrorPageTip("8"));
}
}
}
else
{
//错误15:验证码输入错误,请重新填写
Response.Write("15|" + sysParam.ErrorPageTip("15"));
}
}
{
string checkCode = StringHelp.FilterSpeStr(Request.QueryString["checkcode"]);
if (string.IsNullOrEmpty(checkCode))
{
//验证码丢失
return;
}
//比较验证码是否正确,不区分大小写
if (string.Compare(checkCode, Session["LVNum"].ToString(), true) == 0)
{
string name = Request.QueryString["paramName"];
string pwd = Request.QueryString["paramPwd"];
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(pwd))
{
//错误1:URL解析错误
Response.Write("1|" + sysParam.ErrorPageTip("1"));
}
else
{
DataSet ds = BLL.web_vipuser.GetVip(name);
//用户是否存在
if (Validator.CheckDS(ds, 0))
{
string vipPwd = Tools.Encryption.MD5Encrypt(pwd);
//密码是否正确
if (ds.Tables[0].Rows[0]["password"].ToString() == vipPwd)
{
string state = ds.Tables[0].Rows[0]["state"].ToString();
//账号状态: 1正常 0 未审核
if (state == "0")
{
//此账号未通过管理员审核
Response.Write("21|" + sysParam.ErrorPageTip("21"));
}
else
{
// SetUserCookie(ds.Tables[0]);
Session["VipName"] = ds.Tables[0].Rows[0]["username"];
//登陆成功
Response.Write("10|" + sysParam.ErrorPageTip("10"));
Session.Timeout = 30;
}
}
else
{
//错误9:您输入的密码有误
Response.Write("9|" + sysParam.ErrorPageTip("9"));
}
}
else
{
//错误8:您输入的账号不存在
Response.Write("8|" + sysParam.ErrorPageTip("8"));
}
}
}
else
{
//错误15:验证码输入错误,请重新填写
Response.Write("15|" + sysParam.ErrorPageTip("15"));
}
}