//To jest ten nie dzialajacy ( tak uzywam VS2008 ):
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public class MyButton : Button
{
public string login;
public string pass;
}
public partial class _Default : System.Web.UI.Page
{
private bool logged = false;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
if (!logged)
{
Label log = new Label();
Label pas = new Label();
log.Text = "Username";
pas.Text = "Password";
TextBox login = new TextBox();
TextBox pass = new TextBox();
pass.TextMode = TextBoxMode.Password;
this.form1.Controls.Add(log);
this.form1.Controls.Add(login);
this.form1.Controls.Add(pas);
this.form1.Controls.Add(pass);
MyButton btn = new MyButton();
btn.login = login.Text;
btn.pass = pass.Text;
btn.Width = 100;
btn.Height = 25;
btn.Text = "Log in";
btn.Click += new EventHandler(this.btn_Click); // <---------------------
//btn.Command += new CommandEventHandler(this.btn_Click);
this.form1.Controls.Add(btn);
}
else
{
Response.Redirect("MyAccount.aspx");
}
}
public void btn_Click(Object sender,
EventArgs e) //<---------------------------------
{
Response.Redirect("MyAccount.aspx");
MyButton mybtn = (MyButton)sender;
string log = mybtn.login;
string pass = mybtn.pass;
string connectionString = @"Data Source=TOMMY-PC\SQLEXPRESS;Initial Catalog=tom;Integrated Security=True";
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
string command = "SELECT login, pass FROM Users";
SqlCommand cmd = new SqlCommand(command, connection);
string clog;
string cpas;
bool tmp = true;
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read() && tmp)
{
clog = reader["login"].ToString().Trim();
cpas = reader["pass"].ToString().Trim();
//Response.Redirect("www.netwars.pl");
if (log.Equals(clog) && pass.Equals(pass))
{
tmp = false;
Response.Write("You have been logged in");
}
}
reader.Close();
connection.Close();
logged = true;
}
}
//moze ja juz slepy gdzies jestem ;]