473,549 Members | 3,109 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passwording a PHP page

I'm trying to password the 'update' page of a MySQL database that runs
on a company intranet w/Apache and PHP. I don't care about the
'entry' page to this database - just the 'update' page and want the
five people (or so) who may be doing updates, to enter only a password
and then write that password to the MySQL database field.

On my entry page as the last part of my form, I'm using;
<tr>
<td>Password: </td><td align="left"><i nput type="password"
name="password" size="15" maxlength="15" value=""></td>
</tr>
<tr>
<td colspan="4" align="center"> <input type="submit"
value="Enter"></td>
</tr>
</table>
</form>

What I'm looking for is pointers on how to make the second page of
this work query work based on meeting the criteria of a password
element - i.e: 2nd page

$password = $_POST['password'];

if (!$password = 'password stored in database' allow write))
{
else echo PASSWORD must match file on record for this user;
}
I know this isn't the code precisely but am hopeful for any pointers
in making it happen. Again, I'm not looking for a complete login
since it IS an intranet - just looking to write to the database the
user who did the update (provided the password criteria was met).
TIA...
Jul 10 '07 #1
11 1541
cover wrote:
I'm trying to password the 'update' page of a MySQL database that runs
on a company intranet w/Apache and PHP. I don't care about the
'entry' page to this database - just the 'update' page and want the
five people (or so) who may be doing updates, to enter only a password
and then write that password to the MySQL database field.

On my entry page as the last part of my form, I'm using;
<tr>
<td>Password: </td><td align="left"><i nput type="password"
name="password" size="15" maxlength="15" value=""></td>
</tr>
<tr>
<td colspan="4" align="center"> <input type="submit"
value="Enter"></td>
</tr>
</table>
</form>

What I'm looking for is pointers on how to make the second page of
this work query work based on meeting the criteria of a password
element - i.e: 2nd page

$password = $_POST['password'];

if (!$password = 'password stored in database' allow write))
{
else echo PASSWORD must match file on record for this user;
}
$query="SELECT * FROM table WHERE password_column ='{$_POST['password']}'";
$res=mysql_quer y($query);
if(!mysql_num_r ows($res)) {
echo "sorry, the wrong password";
exit;
}

echo "Wow, you know the password";
--

//Aho
Jul 10 '07 #2
On Tue, 10 Jul 2007 06:07:24 +0200, "J.O. Aho" <us**@example.n et>
wrote:

>$query="SELE CT * FROM table WHERE password_column ='{$_POST['password']}'";
$res=mysql_que ry($query);
if(!mysql_num_ rows($res)) {
echo "sorry, the wrong password";
exit;
}

echo "Wow, you know the password";
not sure if that's quite what I was looking for but I very much
appreciate your reply.

What if we want to allow any one of five people to update ANY record
in the db provided they have a password as verified by 'password_tbl'.
The entries won't have any password associate but when someone does an
update, we want to know who did it and write it to the database in the
'updater' field accordingly - thanks...
Jul 10 '07 #3
On Mon, 09 Jul 2007 21:39:08 -0700, cover
<co************ ****@yahoo.comw rote:
>On Tue, 10 Jul 2007 06:07:24 +0200, "J.O. Aho" <us**@example.n et>
wrote:

>>$query="SELEC T * FROM table WHERE password_column ='{$_POST['password']}'";
$res=mysql_qu ery($query);
if(!mysql_num _rows($res)) {
echo "sorry, the wrong password";
exit;
}

echo "Wow, you know the password";
So as I look at this again, perhaps the user logs in their first name
and in the table password_tbl a password exists that corresponds with
their first name. So is that:

$query="SELECT * FROM $table WHERE
firstname_colum n='{$_POST['firstname']}'" AND;
password_column ='{$_POST['password']}'";
$res=mysql_quer y($query);
if(!mysql_num_r ows($res)) {
echo "sorry, the wrong password";
exit;
}
echo "Wow, you know the password";
Jul 10 '07 #4
cover wrote:
On Tue, 10 Jul 2007 06:07:24 +0200, "J.O. Aho" <us**@example.n et>
wrote:

>$query="SELE CT * FROM table WHERE password_column ='{$_POST['password']}'";
$res=mysql_que ry($query);
if(!mysql_num_ rows($res)) {
echo "sorry, the wrong password";
exit;
}

echo "Wow, you know the password";

not sure if that's quite what I was looking for but I very much
appreciate your reply.
I think that is what you wanted, a check of the password against what is in
the database, the mysql_num_rows returns how many lines there is with the
password, if it returns 0, then you know the passowrd was either misspelled or
the person didn't know the password.
You execute the db-update after the password check.

What if we want to allow any one of five people to update ANY record
in the db provided they have a password as verified by 'password_tbl'.
The entries won't have any password associate but when someone does an
update, we want to know who did it and write it to the database in the
'updater' field accordingly - thanks...
You will need a log table (or a log file), you can store the query and the
password to the table/file, that way you can check what each person has done.
If you want you could of course store a "user name" in the password table and
use that name in the log file/table.
You may want to make a check of the query before you run it, so that they
aren't affecting the password_tbl or the log_tbl.

IMHO the following flow is a good one:

1. Check login
a. FALSE - redirect the user to another page with header()
b. TRUE - let user execute the rest of the page
2. Check query to be executed
a. BAD - don't execute, redirect user to another page with header()
b. OK - let the execution continue
3. Store query + password/username to the log table/file
4. Execute the query

The page you redirect to can be static (html), which just informs the user
that they done something they shouldn't. I think this is a lot better than
having big if-cases in the main script which can easily make you do
modifications in the wrong place, specially if you have a bad "syntax" use.
--

//Aho
Jul 10 '07 #5
cover wrote:
So as I look at this again, perhaps the user logs in their first name
and in the table password_tbl a password exists that corresponds with
their first name. So is that:

$query="SELECT * FROM $table WHERE
firstname_colum n='{$_POST['firstname']}'" AND;
password_column ='{$_POST['password']}'";
$res=mysql_quer y($query);
if(!mysql_num_r ows($res)) {
echo "sorry, the wrong password";
exit;
}
echo "Wow, you know the password";
Yes, in the case you want that the user will be using both a login name and
password, if you only want a password, you have to see that the password is
unique, otherwise the users can be mixed up (while using login+pass the
likelihood is a lot less that you have two persons with the same login and
password, of course you should see to have only one user for each
username/login you use).

--

//Aho
Jul 10 '07 #6
On Tue, 10 Jul 2007 07:34:35 +0200, "J.O. Aho" <us**@example.n et>
wrote:
>Yes, in the case you want that the user will be using both a login name and
password, if you only want a password, you have to see that the password is
unique, otherwise the users can be mixed up (while using login+pass the
likelihood is a lot less that you have two persons with the same login and
password, of course you should see to have only one user for each
username/login you use).
Would something like this work where there might be two tables, one
with the data you're trying to update and the second only holding the
user name and password where conditions had to be met at update.

mysql_query("UP DATE actions_tbl SET date='$ud_date' ,
targmonth='$ud_ targmonth', targyear='$ud_t argyear',
assignedto='$ud _assignedto', datecomp='$ud_d atecomp',
status='$ud_sta tus', referenceno='$u d_referenceno'
WHERE id='$ud_id' AND WHERE password_tbl
updater_column= '$updater' AND password_column ='$password'") or
die("Update Error: ".mysql_error() );

echo "Record Updated";
mysql_close();

The tricky part appears to be in adding AND WHERE so when 'id'
conditions have been met in the actions_tbl, updater and password
conditions must also be met in password_tbl - I dunno - still have a
syntax issue associated w/ the AND WHERE portion. ;-)
Jul 10 '07 #7
cover wrote:
On Tue, 10 Jul 2007 07:34:35 +0200, "J.O. Aho" <us**@example.n et>
wrote:
>Yes, in the case you want that the user will be using both a login name and
password, if you only want a password, you have to see that the password is
unique, otherwise the users can be mixed up (while using login+pass the
likelihood is a lot less that you have two persons with the same login and
password, of course you should see to have only one user for each
username/login you use).

Would something like this work where there might be two tables, one
with the data you're trying to update and the second only holding the
user name and password where conditions had to be met at update.
mysql_query("UP DATE actions_tbl SET date='$ud_date' ,
targmonth='$ud_ targmonth', targyear='$ud_t argyear',
assignedto='$ud _assignedto', datecomp='$ud_d atecomp',
status='$ud_sta tus', referenceno='$u d_referenceno'
WHERE id='$ud_id' AND WHERE password_tbl
updater_column= '$updater' AND password_column ='$password'") or
die("Update Error: ".mysql_error() );

echo "Record Updated";
mysql_close();
No, that won't work, do

$pass_query="SE LECT * FROM table WHERE password_column ='{$_POST['password']}'
AND user_column='{$ _POST['username']}'";
$res=mysql_quer y($pass_query);
if(mysql_num_ro ws($res)) {
$query="UPDATE actions_tbl SET date='$ud_date' ,
targmonth='$ud_ targmonth', targyear='$ud_t argyear',
assignedto='$ud _assignedto', datecomp='$ud_d atecomp',
status='$ud_sta tus', referenceno='$u d_referenceno'
WHERE id='$ud_id'";
mysql_query($qu ery);
$time=date('Y-m-d h:n');
shell_exec("ech o \"{$time} {$_POST['username']}: {$query}\" >>
/path/to/sqlupdate.log") ;
}

This way you check if the user is allowed to make the update and up do the
update and then register the update to the logfile.
--

//Aho
Jul 10 '07 #8
On Tue, 10 Jul 2007 06:07:24 +0200, "J.O. Aho" <us**@example.n et>
wrote:
>$query="SELE CT * FROM table WHERE password_column ='{$_POST['password']}'";
$res=mysql_que ry($query);
if(!mysql_num_ rows($res)) {
echo "sorry, the wrong password";
exit;
}

echo "Wow, you know the password";

I started over... Can't seem to get anything but the 'sorry, wrong
password'.

The form writes to a database called 'actions' and a table called
'actions_tbl' and I'd like to continue to write to that table but only
if, the name and password that are queried on the write are consistent
with a name and password stored within the same database but another
table called 'password_tbl'

This particular form is an update form used to update existing records
into the 'actions_tbl' table. I'd like to add two text fields to the
update form ('text' and 'password') and write that to an additional
field I'll be adding in actions_tbl ('updated_by') to know who did the
update. That update person would have to enter a name and password
into the form that is pre-stored in password_tbl to be successful.

Upon writing to the database table actions_tbl, the name and password
would be checked via query of password_tbl to ensure whomever was in
the database and authorized to do an update. The existing update form
works great but again, there could be issues in not knowing who did
the update which leads to the desire to issue a basic login name and
password that would have to be used for updating records in the db.

I'd thought that perhaps somewhat the reverse of not allowing an empty
field to be processed might be on track but realize that a query will
have to be included to actually check the name and password against
what's in password_tbl so my empty field code as follows won't work
but here it is if it should help someone looking for that particular
fix.

if (!$source || !$type || !$area)
{
echo 'You have not entered all the required fields for this data
entry.<br />'
.'Please click the browser BACK button, complete the form
and try again.';
exit;
}

Anyway, thanks for the pointers and sorry if it seems like I'm getting
into rambling here - frustration coming through... lol
Jul 11 '07 #9
cover wrote:
On Tue, 10 Jul 2007 06:07:24 +0200, "J.O. Aho" <us**@example.n et>
wrote:
>$query="SELE CT * FROM table WHERE password_column ='{$_POST['password']}'";
$res=mysql_que ry($query);
if(!mysql_num_ rows($res)) {
echo "sorry, the wrong password";
exit;
}

echo "Wow, you know the password";


I started over... Can't seem to get anything but the 'sorry, wrong
password'.
Forms can be sent in to different ways, POST or GET, this you adjust with the
method-option in the form-tag

<form method="post" ... =$_POST
<form method="get" ... =$_GET

For testing, you can put the following in your script where you receive the form

echo "$_POST: ";
var_dump($_POST );
echo "$_GET: ";
var_dump($_GET) ;

This way you will see the values sent to the page, really useful when debugging.

The form writes to a database called 'actions' and a table called
'actions_tbl' and I'd like to continue to write to that table but only
if, the name and password that are queried on the write are consistent
with a name and password stored within the same database but another
table called 'password_tbl'
// we have checked the empty values

$query="SELECT * FROM password_tbl WHERE
password_column ='{$_POST['password']}' AND user_column='{$ _POST['user']}'";
$res=mysql_quer y($query);
if(!mysql_num_r ows($res)) {
echo "sorry, the wrong password";
exit;
}

// your old code here

I should say it can be good to process the $_POST['password'] and
$_POST['user'] before using the values, checking that no one is trying to
inject SQL code (don't know how bad people working at your job place).

This particular form is an update form used to update existing records
into the 'actions_tbl' table. I'd like to add two text fields to the
update form ('text' and 'password') and write that to an additional
field I'll be adding in actions_tbl ('updated_by') to know who did the
update.
You will need to use an ALTER TABLE, I suggest you create a test table first
and test on it first before you get on the live table.
When you added the columns it's just do it the same way as before.
I'd thought that perhaps somewhat the reverse of not allowing an empty
field to be processed might be on track but realize that a query will
have to be included to actually check the name and password against
what's in password_tbl so my empty field code as follows won't work
but here it is if it should help someone looking for that particular
fix.

if (!$source || !$type || !$area)
{
echo 'You have not entered all the required fields for this data
entry.<br />'
.'Please click the browser BACK button, complete the form
and try again.';
exit;
}

PHP has the empty() function which is used to check values, as values like
"false", "0" will generate a "true" in your if case.

if(empty($sourc e) || empty($type) || empty($area)) {
echo 'You didn't enter all the needed values';
exit;
}
I hope this leads you in the right direction, time for me to get to work and
don't have much time over for ng there.

--

//Aho
Jul 11 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4180
by: Michael Brennan-White | last post by:
If I submit my for using a get action the resulting page loads . If I use a post action I get an error page saying "The page cannot be found". I am calling the originating page!!! This happens in IE as well as FireFox. This code has been tested on a Win2003 server, IIS6, PHP 5.0.3, mySQL 4.1.8 and it works fine. The problem server is...
4
2157
by: Michael Lamb | last post by:
Hello! I am having trouble passwor protecting a page! i want a simple script that will allow me to have more than one 'account' but will also hide the destination page within the script. Any help would be much appreciated! Michael Newcastle - UK
7
1419
by: Chris | last post by:
I have a PHP query for a MySQL database that I'd like to restrict access to. It's linked from a .htm webpage with other links on a company intranet site. Does anyone know of any PHP code examples on the net to perform such a task? I have to think it's a pretty common application for passwording in PHP. thanks, Chris
0
2414
by: Nathan | last post by:
Hi, I seem to having a peculiar problem with the display of odd and even pages in XSL-FO. Here is a small background of the problem. My xsl stylesheet mentions my fo:layout-master-set as <fo:layout-master-set> <fo:simple-page-master margin-left="0.5in" margin-right="0.5in" page-width="8.5in" margin-bottom="0.5in"...
2
4328
by: James | last post by:
I've been to websites where if I navigate off a form, trying to get back to it by hitting the back button gives me a page which says "Warning, page has expired". It doesn't display the page. I've been searching around trying to get this to happen for one of my aspx pages and I can't get it to expire. I've put the following HTML tags in the...
4
2793
by: Kevin Phifer | last post by:
Ok, before anyone freaks out, I have a solution I need to create that gathers content from maybe different places. Each one can return a <form> in the html, so its the classic can't have more than one runat=server form on a asp.net page. However, I still want developers to be able to use asp.net controls to create some apps that are created...
2
3608
by: John Lau | last post by:
Hi, Is there documentation that talks about the page lifecycle, the lifecycle of controls on the page, and the rendering of inline code, in a single document? Thanks, John
6
2941
by: MooreSmnith | last post by:
When I navigate to the next page using Response.Rediect("MyNextPage.aspx") current page Page_Load event is called. What I may wrongly understood is that post back will happen whenever there is any server side event happens, resulting in Page_load event. Page_Load is also happening when I navigate to the next page. That means Page_load will...
1
2259
by: Lenard Gunda | last post by:
Hi! I have the following problem. From my main page, when someone clicks a button, it uses client side javascript to open another .aspx page. This page displays content, based on what the first page is set to show. If you change the first page, and click the button again, the newly opened page will show other things. Nothing special. It...
0
7520
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7956
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7809
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6041
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1936
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1058
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.