[英]Using C# to add stored procedures from solution folder to SQL Server database
[英]how to add a database field in the c# code without using stored procedures in a disconnected architecture
我需要在asp.net中創建登錄頁面,我必須在其中創建3個用戶訪問級別,例如
可以查看電子郵件和更新超級用戶的用戶可以查看電子郵件,更新並刪除超級用戶的用戶admin可以查看全部和刪除超級用戶的用戶admin。
我的登錄頁面上有用戶名密碼和登錄按鈕
當用戶/管理員/超級用戶單擊按鈕時,它應根據用戶級別自動重定向。
我有一個用戶名,密碼,用戶名,用戶訪問類型,電子郵件的數據庫。 我的問題在這里,我沒有得到如何在斷開連接的數據庫體系結構中以及不使用存儲過程的情況下基於用戶訪問類型編寫if命令。
String Uid = TextBox1.Text;
String Pwd = TextBox2.Text;
SqlConnection con = new SqlConnection(@"Data Source=Sun-PC\SQLEXPRESS;Initial Catalog=dts;Persist Security Info=True;User ID=sa;Password=********;");
SqlDataAdapter da;
da = new SqlDataAdapter("Select userid,password,useraccesstype from Table2 WHERE userid = " + Uid + " and password ='" + Pwd + "'", con);
DataSet ds = new DataSet("Table2");
da.Fill(ds, "Table2");
if (Uid == "userid" && Pwd == "password")
{
if (uzrtype3 = "componentadmin")
{
Response.Redirect("userpage.aspx");
}
if (uzrtype = "user")
{
Response.Redirect("register.aspx");
}
}
else
{
Label123.Text = "Sorry, user not recognized - please try again";
}
閱讀這句話,我想你是在問“如何獲得用戶訪問類型”? 如果使用當前代碼 ,可能是:
if(ds.Tables[0].Rows.Count == 1) {
// match
var accessType = ({appropriate cast here})ds.Tables[0].Rows[0]["useraccesstype"];
} else {
// no match
}
然而! 我將以另一種方式進行操作,解決各種參數問題並使其更加安全-使用“ dapper-dot-net”為方便起見(使用Google):
string userid = ....
string password = ...
var row = con.Query(
"Select useraccesstype from Table2 WHERE userid = @userid and password = @password",
new { userid, password }).FirstOrDefault();
if(row == null) {
// no match
} else {
var accessType = ({some cast here})row.useraccesstype;
}
鹽化的哈希密碼也是您應該研究的內容。
沒有意義返回用戶名/密碼:您已經知道了。 您也可以使用ExecuteScalar,但隨后需要自己處理參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.