PHP programming without using SQL- Present a page ( start.html ) to the user. Th
ID: 3749064 • Letter: P
Question
PHP programming without using SQL-
Present a page (start.html) to the user. This page should have a form with 2 fields, login name and password. Hide the text for the password. There should be a button to login. There should also be a separate link to create an account. The login button should connect to login.php
When the user clicks on the create account button, they should go to “createAccount.html”. This page should have a form with 2 fields, login name and password. Hide the text for the password. There should be a button to submit. This submit button should connect to “createAccount.php”.
createAccount.php should read in the list of current users from the file “pass.txt”. If the user name already exists, inform the user that they can not use the name that they chose and present them with a link back to createAccount.html. If the user name did not already exist, add this account to the pass.txt file.
pass.txt should have the format “username:SHA-1(password)”
Do not save plain text passwords, you must store the Hash of the password.
After the new account has been created, present a link to a file accessData.html
accessData.html should have two buttons (no input) – use 2 forms. The first button connects to addRecord.html. The second button connects to searchRecords.html.
addRecord.html should present a form with 3 inputs, first name, last name, and phone number. There should be a submit button and a clear button. The submit button should connect to a file addRecord.php.
addRecord.php should open a file “employees.txt” for append mode. It should add the employee record to the end of the file in the format “Lastname:Firstname:Phone”. A message should be displayed that indicates success. Also a link should be provided back to accessData.html.
searchRecords.html should have a form with a single text box for last name. You should have a submit and clear button. The submit button should connect to a file searchRecords.php
searchRecords.php should read the file “employees.txt” into an array. Search through the array, and display the last name, first name, and phone number for every employee that matches the last name that was submitted to this page. Use a table to display the information. A link should be presented that links back to accessData.html.
login.php should check that the given user name exists in the pass.txt file. It should also calculate the SHA-1 hash of the given password. If the user name and hashed password pair match, provide a link to the user to the accessData.html page. If they do not exist, print and error message, with a link back to the start.html page.
Explanation / Answer
//Sample code here for understanding, as it is complete project discussion required
//Registeration page
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Drawing;
public partial class _Default : System.Web.UI.Page
{
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
//create a connection with data base
SqlConnection con = new SqlConnection(@"Data Source=.;AttachDbFilename=|DataDirectory|Database.mdf;Integrated Security=True;User Instance=True;");
//open connection
con.Open();
//specify sql command
SqlCommand cmd = new SqlCommand("select*from regform where username='" + TextBox1.Text + "'", con);
//Sends the CommandText to the Connection and builds a SqlDataReader
SqlDataReader dr = cmd.ExecuteReader();
//validate user exists
if (dr.Read())
{
Label1.Text = "User Name is Already Exist";
this.Label1.ForeColor = Color.Red;
}
else
{
Label1.Text = "UserName is Available";
this.Label1.ForeColor = Color.Red;
}
con.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
captcha1.ValidateCaptcha(TextBox6.Text.Trim());
if (captcha1.UserValidated)
{
//using captcha from data base
SqlConnection con = new SqlConnection(@"Data Source=.;AttachDbFilename=|DataDirectory|Database.mdf;Integrated Security=True;User Instance=True;");
con.Open();
SqlCommand cmd = new SqlCommand("insert into regform values(@a,@b,@c,@d)",con);
cmd.Parameters.AddWithValue("a", TextBox1.Text);
cmd.Parameters.AddWithValue("b", TextBox2.Text);
cmd.Parameters.AddWithValue("c", TextBox4.Text);
cmd.Parameters.AddWithValue("d", TextBox5.Text);
cmd.ExecuteNonQuery();
Session["name"] = TextBox1.Text;
Response.Redirect("default.aspx");
con.Close();
}
else
{
Label2.ForeColor = System.Drawing.Color.Red;
Label2.Text = "You have Entered InValid Captcha Characters please Enter again";
}
}
}
//Login page
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
05
using System.Data.SqlClient;
using System.Drawing;
public partial class login : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
//connection to data base
SqlConnection con = new SqlConnection(@"Data Source=.;AttachDbFilename=|DataDirectory|Database.mdf;Integrated Security=True;User Instance=True;");
//open connection
con.Open();
SqlCommand cmd = new SqlCommand("select COUNT(*)FROM regform WHERE username='"+ TextBox1.Text + "' and password='" + TextBox2.Text + "'");
cmd.Connection = con;
int OBJ = Convert.ToInt(cmd.ExecuteScalar());
//validation of username password
if (OBJ > 0)
{
Session["name"] = TextBox1.Text;
Response.Redirect("default.aspx");
}
else
{
Label1.Text = "Invalid username or password";
this.Label1.ForeColor = Color.Red;
}
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
Response.Redirect("Registration.aspx");
}
}
using System;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.