I was doing my asp.net c# project for my academic submission. And I'm trying to build a Approval for Registrations in the site. For this i have created a new column in database with bit type ( column approval).
And i was trying to check when a user sign in, a IF statement is used to check whether the " approval column is true or false, if true then execute the login instructions. Else pop up message stating " admin approval pending"
here is my code
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.Web.Security;
public partial class dlgn : System.Web.UI.Page
{
DbConnect db = new DbConnect();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
db.con.Open();
db.cmd = new SqlCommand("select approval,email,type from docreg where email='" + username.Text + "'and password='" + password.Text + "'", db.con);
SqlDataReader reader = null;
reader = db.cmd.ExecuteReader();
if (reader.HasRows)
{
bool approval;
approval = reader.GetBoolean(0);
if (approval == true)
{
reader.Read();
Response.Write("<script>alert('Login successful')</script>");
Session["sid"] = username.Text.ToString();
Session["email"] = reader.GetString(0).ToString();
Session["type"] = reader.GetString(0).ToString();
Session["name"] = reader.GetString(0).ToString();
FormsAuthenticationTicket ticket = default(FormsAuthenticationTicket);
string cookie = null;
HttpCookie httpCookie = default(HttpCookie);
ticket = new FormsAuthenticationTicket(1, username.Text, DateTime.Now, DateTime.Now.AddMinutes(100), true, HiddenCustomerID.Value, "MyPage");
cookie = FormsAuthentication.Encrypt(ticket);
httpCookie = new HttpCookie(FormsAuthentication.FormsCookieName, cookie);
httpCookie.Path = FormsAuthentication.FormsCookiePath;
Response.Cookies.Add(httpCookie);
Response.Redirect("dochme.aspx");
}
else
{
Response.Write("<script>alert('Your Profile Not Yet Approved by Admin, kindly Check back later ')</script>");
}
}
else
{
Response.Write("<script>alert('Invalid username or password')</script>");
}
}
}