0
私のプロジェクトでは、ログインを実装しています。
ページlogin.aspxのページが含まれています標準ログインをweb.configに関連させない方法は?
<asp:Login ID="MainLogin" runat="server" onloggingin="MainLogin_LoggingIn"></asp:Login>
サーバ側でこのページ:私は、セッション変数に書き込む後で必要
protected void MainLogin_LoggingIn(object sender, LoginCancelEventArgs e)
{
if (FormsAuthentication.Authenticate(MainLogin.UserName, MainLogin.Password))
{
FormsAuthentication.RedirectFromLoginPage(MainLogin.UserName, MainLogin.RememberMeSet);
if (FormsAuthentication.Authenticate(MainLogin.UserName, MainLogin.Password))
{
SqlConnection myConnection = new SqlConnection(DBConnection.GetConnectionString());
SqlCommand myCommand = new SqlCommand("SELECT * FROM Users WHERE [email protected] and [email protected]", myConnection);
myCommand.Parameters.AddWithValue("login", MainLogin.UserName);
myCommand.Parameters.AddWithValue("pass", MainLogin.Password);
myCommand.Connection.Open();
SqlDataReader Reader = myCommand.ExecuteReader();
while (Reader.Read())
{
Session["curUserRole"] = Reader["role"].ToString();
Session["curUserLogin"] = MainLogin.UserName;
Server.Transfer(Request.Url.LocalPath);
FormsAuthentication.RedirectFromLoginPage(MainLogin.UserName, MainLogin.RememberMeSet);
return;
}
//Reader.Close();
//myCommand.Connection.Close();
//myConnection.Close();
}
else {
}
}
変数を。 web.configファイルで は私が持っている:
<authentication mode="Forms">
<forms loginUrl="Login.aspx">
<credentials passwordFormat="Clear">
<user name="Admin" password="sa" />
</credentials>
</forms>
</authentication>
<authorization>
<allow roles="Admin"/>
<deny users="?"/>
</authorization>
は、だから私は、ログイン入力された - 「管理者」をし、合格 - アイテムのユーザーを見つけた場合、「SA」は、それがweb.configファイルにチェックし、それがデータベースにこの項目をチェックし、私はデータベース内のチェック項目だけを必要とし、そこにロードスタートアップページがある場合は、もう一度Login.aspxをロードします。あなたが望むように
本当にわかりませんユーザー名はDB内で暗号化され、Clear Textでは暗号化されません。あなたはあなたが基本的なフォーム認証をしようとしていることから、これは正しいですか?またセッションオブジェクトに値を代入する前にDBクエリから返された値があるかどうかをチェックしていません。これは私たちがすべて負の仮定をしています – MethodMan
Doパスワードをプレーンテキストで保存しないでください。組み込みのSqlMembershipProviderを使用する必要があります。 – SLaks
ここでクリアテキストで、私はシャットダウンを暗号化します。後でそのユーザータイプでDBから暗号化されたパスまたはログインを管理できます。あなたは実際にweb.confogに書き込む必要はありません –