PDA

View Full Version : مشکل در کد لاگین



shahram176
جمعه 30 آبان 1393, 23:03 عصر
سلام
من در قسمت ورود سایت کد زیر را نوشتم که از جدول کاربران چک کنه که اگر کاربره بره به صفحات کاربری اگه نبود بره جدول مدیریت را چک کنه اگه مدیر بود بره به صفحات مدیریت اگر نه کار بر نه مدیر بود بنویسه نام کاربری یا رمز عبور اشتباه است کد زیر را نوشتم نمیدونم کجاش را اشتباه نوشتم؟
using System;using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Security.Cryptography;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;


namespace eshop
{
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{


}


protected void ImageButton5_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect("Enrollment.aspx");
}


protected void ImageButton4_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect("sendPass.aspx");
}


protected void ImageButton6_Click(object sender, ImageClickEventArgs e)
{
string str = TextBox1.Text;
byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes(str);
SHA256Managed sha = new SHA256Managed();
byte[] hashValue = sha.ComputeHash(data);
string strp = "";
foreach (byte strb in hashValue)
{
strp += strb.ToString();
}
string s = (TextBox4.Text);

string strConnection = WebConfigurationManager.ConnectionStrings["eshopConnectionString1"].ToString();
SqlConnection con = new SqlConnection(strConnection);
string strCmd = " select username,password from tUser where username=@u and password=@p";
SqlCommand cmd = new SqlCommand(strCmd, con);
SqlDataReader reader;
cmd.Parameters.AddWithValue("@u", TextBox4.Text);
cmd.Parameters.AddWithValue("@p", strp);
try
{
con.Open();


reader = cmd.ExecuteReader();
if (reader.Read())
{

Session["karbar"] = TextBox4.Text;
}

else
{
strCmd = " select username,password from tAdmin where username=@u and password=@p";
cmd = new SqlCommand(strCmd, con);
cmd.Parameters.AddWithValue("@u", TextBox4.Text);
cmd.Parameters.AddWithValue("@p", TextBox1.Text);


try
{
con.Open();


reader = cmd.ExecuteReader();
if (reader.Read())
{


Session["admin"] = TextBox4.Text;
}


else
{
Label1.Text = "چنین کلمه عبوری وجود ندارد";
con.Close();
return;
}


}






catch
{
Label1.Text = "خطا در ورود";
con.Close();
return;
}
}


}





catch
{
Label1.Text = "خطا در ورود";
con.Close();
return;
}



Response.Redirect("Message.aspx?id=3");
}
}
}

shahram176
چهارشنبه 05 آذر 1393, 19:52 عصر
دوستان لطفا کمک کنید