首页 新闻 会员 周边

关于登录页面的验证的问题

0
[待解决问题]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    public SqlConnection GetConnection()
    {
        string myStr = "Data Source=.\\sqlexpress;Initial Catalog=mySQL;Integrated Security=True";
        SqlConnection myConn = new SqlConnection(myStr);
        return myConn;
    }
    protected void enter_Click(object sender, EventArgs e)
    {
            SqlConnection myConn = GetConnection();
            myConn.Open();
            SqlParameter[] parameters = new SqlParameter[]
            {
                new SqlParameter("@number",SqlDbType.NVarChar ,50){Value =usernameTB .Text },
                new SqlParameter ("@password",SqlDbType .NVarChar,50){Value =userpasswordTB .Text },
            };
            string sqlstr = "select * from userfome where usernumber=@number and userpassword=@password";
            SqlCommand mycmd = new SqlCommand(sqlstr, myConn);
            mycmd.Parameters.AddRange(parameters);
            //SqlDataReader dr = mycmd.ExecuteReader();
            if (mycmd.ExecuteScalar() != null)
            {
                Response.Redirect("~/聊天窗口/over.aspx");
            }
            else
            {
                Response.Write("哈哈哈,登录失败了吧!");
            }
            myConn.Close();
            myConn.Open();
            SqlDataReader rd = mycmd.ExecuteReader(CommandBehavior.CloseConnection);
            while (rd.Read())
            {
                Application["Username"] = rd["username"];
                Application["Usersex"] = rd["usersex"];
            }
            myConn.Close();
    }
    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
    {

    }
    protected void lon_Click(object sender, EventArgs e)
    {
        goodjob(false);
        Response.Redirect("~/登录验证/login.aspx");
    }

这 是 我写的登录页面的代码,我现在郁闷的就是,即使点注册,验证控件也会验证一下textbox里的内容是否为空。      我这里问题应该还会有,如果发现了,就指出来,我以后注意。

返回值X的主页 返回值X | 初学一级 | 园豆:6
提问于:2014-04-23 08:22
< >
分享
所有回答(3)
0

用jQuery的插件验证啊,比如:Validform,jquery.validation等

FlowerH | 园豆:230 (菜鸟二级) | 2014-04-23 08:57
0

太粗糙的登录了

许大虾 | 园豆:12 (初学一级) | 2014-04-24 13:58

确实很粗糙,我也在不断努力,能不能帮帮我?

支持(0) 反对(0) 返回值X | 园豆:6 (初学一级) | 2014-04-24 20:34

@返回值X: 建议你去了解下Ajax,JS,COOKIE,Session ...

然后熟悉了,通过这些来做一个登录。。。

支持(0) 反对(0) 许大虾 | 园豆:12 (初学一级) | 2014-04-24 23:37
0

1.才一个查询,两次打开关闭SqlConnection对象。

2.验证控件在asp页面显示的,不是在asps.cs文件显示的,所以你发的文件我无法查看错误。

3.查询语句,注意数据唯一性,要不然会出现两条以上数据,会报错。

4.sql数据操作,建议封装成一个类。参考微软的sqlhelper。

 

wongdavid | 园豆:394 (菜鸟二级) | 2014-04-27 01:46
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册