`
xylw
  • 浏览: 57999 次
  • 性别: Icon_minigender_1
  • 来自: 南宁
文章分类
社区版块
存档分类
最新评论

加密锁程序

阅读更多
aspx页面

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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 runat="server">
    <title>登录页面——SQL、ACCESS二合一</title>
</head>

<script language="javascript" type="text/javascript">
function login_onclick()
{
var DevicePath,mylen,ret;
    try
    {
        var s_simnew31=new ActiveXObject("Syunew6A.s_simnew6");
    DevicePath = s_simnew31.FindPort(0);
    if( s_simnew31.LastError!= 0 )
    {
    window.alert ( "未发现加密锁,请插入加密锁");
    }
    else
    {
    ret=s_simnew31.YRead(0,1,"ffffffff","ffffffff",DevicePath);
mylen =s_simnew31.GetBuf(0);
form1.Userid.value=s_simnew31.YReadString(1,mylen, "ffffffff", "ffffffff", DevicePath);
            form1.name.value=s_simnew31.YReadString(1,mylen, "ffffffff", "ffffffff", DevicePath);
           
ret=s_simnew31.YRead(20,1,"ffffffff","ffffffff",DevicePath);
mylen =s_simnew31.GetBuf(0);
form1.Pwd.value=s_simnew31.YReadString(21,mylen,"ffffffff", "ffffffff", DevicePath);
            form1.pwd1.value=s_simnew31.YReadString(21,mylen,"ffffffff", "ffffffff", DevicePath);
    }
    } catch (err) {
     txt="错误,原因是" + err.description + "\n\n" 
     txt+="请检查是否安装驱动程序"
     alert(txt) 
    }
}
</script>

<body>
    <form id="form1" runat="server">
        <div>
            用户名:<asp:TextBox ID="Userid" runat="server" ReadOnly="True"></asp:TextBox>
            <br />
            密 码:<asp:TextBox ID="Pwd" runat="server" TextMode="Password" ReadOnly="True"></asp:TextBox>
            <asp:Label ID="Msg" runat="server" ForeColor="Red"></asp:Label><br />
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="SQL登录" />&nbsp;
            <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="ACCESS登录" />
            <br />
            数据库里只有一条数据<br />
            用户名:123<br />
            密码:1234<br />
            <br />
            看很多同学都问我登录页面怎么做,这里给个简单的例子,可以借鉴一下。<br />
            <br />
            SQL和ACCESS的都有,自己看。<br />
            <h3>
                以后有什么不懂的多问问<a href="http://www.baidu.com" target="_blank">百度</a> ,每个人都来问我我也回答不了那么多,有些我也要自己查,大家互相学习吧!</h3>
        </div>
        <asp:HiddenField ID="name" runat="server" />
        <asp:HiddenField ID="pwd1" runat="server" />
    </form>
</body>
</html>



aspx.cs文件

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using System.Data.Common;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.ClientScript.RegisterStartupScript(Page.GetType(), "Message", "<script language='javascript' defer>login_onclick();</script>");
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string username = name.Value;
        string pwd = pwd1.Value;
        //SQL数据库登录
        string ConnStr = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.mdf;Integrated Security=True;User Instance=True";//SQL数据库连接字符串

        string sql = "select count(*) from [user] where username='" + username + "' and password='" + pwd + "'";//执行查询的SQL语句

        SqlConnection SqlCon = new SqlConnection(ConnStr);
        SqlCon.Open();
        SqlCommand SqlCmd = new SqlCommand(sql, SqlCon);
        int count = Convert.ToInt32(SqlCmd.ExecuteScalar());
        if (count > 0)
        {
            Msg.Text = "SQL登录成功";
        }
        else
        {
            Msg.Text = "SQL登录失败";
        }
        SqlCon.Close();
    }


    protected void Button2_Click(object sender, EventArgs e)
    {
        //ACCESS数据库登录
        string ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(".") + "\\App_Data\\db1.mdb;";//ACCESS数据库连接字符串

        OleDbConnection oleConnection = new OleDbConnection(ConnStr);
        oleConnection.Open();
            OleDbCommand mycommand = new OleDbCommand("select count(*) from [user] where username='" + Userid.Text + "' and password='" + Pwd.Text + "'", oleConnection);
            int count = Convert.ToInt32(mycommand.ExecuteScalar());
            if (count > 0)
            {
                Session["name"] = Userid.Text;
                Session["role"] = "Admin";
                Response.Redirect("Admin/AddTeacher.aspx");
            }
            else
            {
                Msg.Text = "ACCESS登录失败";
            }
        oleConnection.Close();

    }
}
分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

Global site tag (gtag.js) - Google Analytics