<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>LoginPage</title>
<script type="text/javascript">
function form_validate() {
if (document.getElementById("<%=Txt_userid.ClientID%>").value == "") {
alert("Please enter UserId");
document.getElementById("<%=Txt_userid.ClientID%>").focus();
return false;
}
if (document.getElementById("<%=Txt_password.ClientID %>").value == "") {
alert("please enter password");
document.getElementById("<%=Txt_password.ClientID %>").focus();
return false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
User Id<asp:TextBox ID="Txt_userid" runat="server"
MaxLength="15" CssClass="Txtbox"> </asp:TextBox>
Password <td><asp:TextBox ID="Txt_password" runat="server"
TextMode="Password" MaxLength="15" CssClass="Txtbox" ></asp:TextBox>
<asp:Button ID="Btn_Submit" runat="server" Text="Login"
onclick="Btn_Submit_Click" OnClientClick="return form_validate()" />
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class Login : System.Web.UI.Page
{
DataClassesDataContext db = new DataClassesDataContext();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Txt_userid.Text = "";
Txt_userid.Focus();
}
}
protected void Btn_Submit_Click(object sender, EventArgs e)
{
try
{
var count = (from myuser in db.Users
from mypass in db.Passwords
where (myuser.Id == Convert.ToInt32(Txt_userid.Text) && myuser.Password == Txt_password.Text)
|| (mypass.UId == Convert.ToInt32(Txt_userid.Text) && mypass.Pass == Txt_password.Text)
select myuser.Id).Count();
if (count > 0)
{
Session["UserId"] = Txt_userid.Text;
IQueryable<int> que = from r in db.RolePages
join u in db.Users on r.RoleId equals u.Role_Id
where r.RoleId == u.Role_Id && u.Id == Convert.ToInt32(Txt_userid.Text)
select r.RoleId;
foreach (int i in que)
{
Session["rolid"] = i;
}
form_load();
}
else
{
ScriptManager.RegisterStartupScript(this, GetType(), "msg", "<script>alert('Invalid Login');</script>", false);
Txt_password.Focus();
}
}
catch
{
throw;
}
}
private void form_load()
{
if(Session["rolid"].ToString()=="2")
{
Response.Redirect("Vulnerabilities.aspx", false);
}
else
{
Response.Redirect("SearchPage.aspx", false);
}
}
}
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>LoginPage</title>
<script type="text/javascript">
function form_validate() {
if (document.getElementById("<%=Txt_userid.ClientID%>").value == "") {
alert("Please enter UserId");
document.getElementById("<%=Txt_userid.ClientID%>").focus();
return false;
}
if (document.getElementById("<%=Txt_password.ClientID %>").value == "") {
alert("please enter password");
document.getElementById("<%=Txt_password.ClientID %>").focus();
return false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
User Id<asp:TextBox ID="Txt_userid" runat="server"
MaxLength="15" CssClass="Txtbox"> </asp:TextBox>
Password <td><asp:TextBox ID="Txt_password" runat="server"
TextMode="Password" MaxLength="15" CssClass="Txtbox" ></asp:TextBox>
<asp:Button ID="Btn_Submit" runat="server" Text="Login"
onclick="Btn_Submit_Click" OnClientClick="return form_validate()" />
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class Login : System.Web.UI.Page
{
DataClassesDataContext db = new DataClassesDataContext();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Txt_userid.Text = "";
Txt_userid.Focus();
}
}
protected void Btn_Submit_Click(object sender, EventArgs e)
{
try
{
var count = (from myuser in db.Users
from mypass in db.Passwords
where (myuser.Id == Convert.ToInt32(Txt_userid.Text) && myuser.Password == Txt_password.Text)
|| (mypass.UId == Convert.ToInt32(Txt_userid.Text) && mypass.Pass == Txt_password.Text)
select myuser.Id).Count();
if (count > 0)
{
Session["UserId"] = Txt_userid.Text;
IQueryable<int> que = from r in db.RolePages
join u in db.Users on r.RoleId equals u.Role_Id
where r.RoleId == u.Role_Id && u.Id == Convert.ToInt32(Txt_userid.Text)
select r.RoleId;
foreach (int i in que)
{
Session["rolid"] = i;
}
form_load();
}
else
{
ScriptManager.RegisterStartupScript(this, GetType(), "msg", "<script>alert('Invalid Login');</script>", false);
Txt_password.Focus();
}
}
catch
{
throw;
}
}
private void form_load()
{
if(Session["rolid"].ToString()=="2")
{
Response.Redirect("Vulnerabilities.aspx", false);
}
else
{
Response.Redirect("SearchPage.aspx", false);
}
}
}
No comments:
Post a Comment