asp.net c# sistem login (asp.net c# login system)


問題描述

asp.net c# sistem login (asp.net c# login system)

i am devolping system with login system there is three types of security level user ,manager ,Administrator and the system user will be over 1500 user so i am some how new to asp.net so i make some soultion to override the membership system in asp.net cause i find it so combliecated  my user table stracture is

user_id int
user_pass int
user_level int    there will be one of three values in this column 1 or 2 or 3

and my web config authanitcation part is

<authentication mode="Forms">

    <forms loginUrl="login.aspx" name="3345C" timeout="60" protection="All" >
        <credentials passwordFormat="Clear">
            <user name="nissadmin" password="nissADM"/>
            <user name="nissuser" password="nissuser"/>
        </credentials>
    </forms>
</authentication>
<location path="oper">
    <system.web>
        <authorization>
            <allow users="nissuser"/>
            <deny users="*"/>
        </authorization>
    </system.web>
</location>
<location path="admin">
    <system.web>
        <authorization>
            <allow users="nissadmin"/>
            <deny users="*"/>
        </authorization>
    </system.web>
</location>      

and my login page code is

protected void Button1_Click(object sender, EventArgs e)
    {
        string connectionString
        = System.Configuration.ConfigurationManager.ConnectionStrings["nisss"].ConnectionString;
        SqlConnection conn = new SqlConnection();
        try
        {
            if (user.Text == "" || pw.Text == "")
            {
                Label1.Text = "Please Fill the required Fields";
            }
            else
            {
                conn = new SqlConnection(connectionString);
                conn.Open();
                SqlCommand cmd = new SqlCommand("logi", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@usr", int.Parse(user.Text)));
                cmd.Parameters.Add(new SqlParameter("@pass", pw.Text));
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet data = new DataSet();
                da.Fill(data);
                if (data.Tables[0].Rows.Count == 1) // if the user and password true
                {
                    int role = data.Tables[0].Rows[0].Field<int>(3);
                    Response.Cookies["id"].Value = user.Text;
                    if (role == 0)
                    {
                        if (System.Web.Security.FormsAuthentication.Authenticate("nissuser", "nissuser"))
                        {
                            system.Web.Security.FormsAuthentication.RedirectFromLoginPage("nissuser", false);
                            Response.Cookies["rolee"].Value = null;
                            Response.Redirect("oper/order.aspx");
                        }

                    }
                    else if (role == 1)
                    {
                        if (System.Web.Security.FormsAuthentication.Authenticate("nissuser", "nissuser"))
                        {
                            System.Web.Security.FormsAuthentication.RedirectFromLoginPage("nissuser", false);
                            Response.Cookies["rolee"].Value = "456";
                            Response.Redirect("oper/order.aspx");
                        }
                    }
                    else if (role == 2)
                    {
                        if (System.Web.Security.FormsAuthentication.Authenticate("nissadmin", "nissADM"))
                        {
                            System.Web.Security.FormsAuthentication.RedirectFromLoginPage("nissadmin", false);
                            Response.Redirect("admin/tabs.html");
                        }
                    }
                }
                else
                {
                    Label1.Text = "wrong password or id";
                }
            }
        }
        finally
        {
            conn.Close();
        }
    }

this works fine on test but all what i need to know is this gonna work with the huge number of users login at the same time without any issues plz help me thanks in advance 

‑‑‑‑‑

參考解法

方法 1:

I would first spike an example of the asp.net forms authentication using the built‑in membership provider. Once you have that working, I would look at sub‑classing the membership provider to customize the security model.

what you have above is way too complicated and you have too many responsibilities in one place.

you may also want to take a look at SimpleMembership Provider

方法 2:

Try to use int.TryParse instead of int.Parse. You never know what users may enter in the field...

(by mr mrJason MeckleyAlex L.)

參考文件

  1. asp.net c# login system (CC BY‑SA 3.0/4.0)

#login #system #ASP.NET #C#






相關問題

只允許 oracle db 登錄到特定的應用程序? (Allowing oracle db login only to specific application?)

使用 FB.login 的註冊流程 (Registration flow using FB.login)

asp.net c# sistem login (asp.net c# login system)

Rails 設計登錄不工作 (Rails devise sign in not working)

我在 cakephp 2.4 中遇到了登錄頁面 (I'm getting stuck with login page in cakephp 2.4)

如何刪除特定用戶的會話登錄 (How to remove session login for specific user)

有沒有標準的asp.net認證授權登錄系統? (Is there a standard asp.net authentication authorization login system?)

所有這些網絡平台如何實現不需要用戶反复登錄的長時間登錄會話? (How do all these web platforms achieve a long-time login session that does not require the user to login over and over again?)

Util-Linux 登錄不使用影子密碼 (Util-Linux Login not working with shadow password)

Android Webview Facebook 登錄 (Android Webview Facebook Login)

重置 Bookstack 憑據 (Reset Bookstack Credentials)

輸入正確的詳細信息且未顯示錯誤後,登錄頁面未重定向到 index.php (Login in page not redirecting to index.php after entering correct details with no error displayed)







留言討論