#region Include Classes
using System;
using System.Threading;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MySql;
using MySql.Web;
using MySql.Data;
using MySql.Data.Common;
using MySql.Data.Entity;
using MySql.Data.Entity.Properties;
using MySql.Data.MySqlClient;
using MySql.Data.MySqlClient.Authentication;
using MySql.Data.MySqlClient.Properties;
using MySql.Data.Types;
#endregion
namespace WebApplication1
{
public partial class Default : System.Web.UI.Page
{
private string tmpStr = String.Empty;
protected void Page_Load(object sender, EventArgs e)
{
try
{
tmpStr = HttpUtility.UrlDecode(Page.ClientQueryString);
Response.Redirect("Cabinet.aspx", true);
if (tmpStr != String.Empty)
{
if (Page.Request.HttpMethod == "GET")
{
if (Page.Request.Params["method"] == "checkAuth")
{
string reqLogin = Page.Request.Params["username"].ToString();
string reqPass = Page.Request.Params["password"].ToString();
bool reqChecked = Convert.ToBoolean(Page.Request.Params["checked"].ToString());
MySQLGear mysqlObject = new MySQLGear();
MySqlConnection mysqlConn = mysqlObject.CreateConnection();
bool userExists = Convert.ToBoolean(mysqlObject.MakeScalar(ref mysqlConn,
"SELECT COUNT(*) FROM `data_user` WHERE username='" + reqLogin + "' AND password='" + reqPass + "'"));
if (userExists)
{
Page.Response.Cookies.Add(new HttpCookie("sessionId", Guid.NewGuid().ToString()));
Page.Response.Cookies.Add(new HttpCookie("clientIp", Page.Request.UserHostAddress.ToString()));
Page.Response.Cookies.Add(new HttpCookie("timeAuth", DateTime.Now.ToString()));
Response.Redirect("Cabinet.aspx", true);
}
else
{
Page.ClientScript.RegisterStartupScript(GetType(), "", "showDialog('Error', 'You have encountered a critical error.', 'error', 2);", true);
}
}
}
else if (Page.Request.HttpMethod == "POST")
{
}
}
}
catch (ThreadAbortException)
{
// ignore it, because we know that come from the redirect
}
catch (Exception exc)
{
exc.ToString();
}
}
}
}