p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Login Script...


Message #1 by "KayKay-GG \(E-mail\)" <kaykay@g...> on Sat, 19 Oct 2002 09:27:44 +0530
Hi,
	I'm just having some trouble with authenticating usernames... Here's how it
is right now...

username=test
password=abcdefg
encrypted password in mySQL = 8687677

What works:
select * from users where user='test';
select * from users where password='8687677';
select * from users where user='test' AND password='8687677';

What doesn't work (returns an empty set):
select * from users where password=password('abcdefg');
select * from users where user='test' AND password=password('abcdefg');

the password and the encrypted form of it are correct - I created a
duplicate record to verify them.... So I'm not too sure what's going on...

Any and all help is appreciated :)
-K



Message #2 by "Trey Carroll" <treycarroll@y...> on Sat, 19 Oct 2002 22:55:00
Looks like you are asking for the row where password is abcdefg, instead 
of 8687677.

Did you mean:
select * from users where user='test' AND password=password('8687677');
?

> Hi,
	I'm just having some trouble with authenticating usernames... 
Here's how it
is right now...

username=test
password=abcdefg
encrypted password in mySQL = 8687677

What works:
select * from users where user='test';
select * from users where password='8687677';
select * from users where user='test' AND password='8687677';

What doesn't work (returns an empty set):
select * from users where password=password('abcdefg');
select * from users where user='test' AND password=password('abcdefg');

the password and the encrypted form of it are correct - I created a
duplicate record to verify them.... So I'm not too sure what's going on...

Any and all help is appreciated :)
-K



Message #3 by "KayKay-GG \(E-mail\)" <kaykay@g...> on Mon, 21 Oct 2002 11:01:45 +0530
Hey Joe ;)
	Thanks for the reply. The password() function is not a PHP function - it's
a MySQL function, which is probably why you can't find any references to it
in PHP manuals :)
	The password() function (on testing) returns the same value for the same
string - password('abcdefg') will always return the same string - so to
compare passwords, you will be doing something like this:

if (password($entered_password) == $stored_password)

You get $stored_password from a MySQL query.

BTW This is how it's explained in the book as well - so I don't know why it
doesn't seem to be working for me :(

Thanks mate,
-K
P.S I'm cc:ing this to the mailing list as well :)

>>>>-----Original Message-----
>>>>From: BTS Technologies, Ltd. [mailto:sureshot@c...]
>>>>Sent: 21 October 2002 11:44
>>>>To: kaykay@g...
>>>>Subject: FW: beginning_php digest: October 19, 2002
>>>>
>>>>
>>>>Hi KayKay,
>>>>
>>>>I'm not familiar with the password() function off hand, but
>>>>I ran into a
>>>>similar problem on a java project.  It turned out that the password
>>>>encryption function used the userID as well as the
>>>>password.  When we
>>>>encrypted a default password for all users of "password4u"
>>>>it was different
>>>>from when each user encrypted the password since it used
>>>>the userID in the
>>>>encryption process - giving different encrypted strings for
>>>>each user even
>>>>though the password was the same.
>>>>
>>>>I didn't see anything in the PHP docs on a password()
>>>>function.  Is it
>>>>something you (or someone else) has written?
>>>>
>>>>Let me know if this helps.
>>>>
>>>>Joe
>>>>
>>>>------------------------------------------------------------
>>>>----------
>>>>
>>>>Subject: Login Script...
>>>>From: "KayKay-GG \(E-mail\)" <kaykay@g...>
>>>>Date: Sat, 19 Oct 2002 09:27:44 +0530
>>>>X-Message-Number: 3
>>>>
>>>>Hi,
>>>>	I'm just having some trouble with authenticating
>>>>usernames... Here's how it
>>>>is right now...
>>>>
>>>>username=test
>>>>password=abcdefg
>>>>encrypted password in mySQL = 8687677
>>>>
>>>>What works:
>>>>select * from users where user='test';
>>>>select * from users where password='8687677';
>>>>select * from users where user='test' AND password='8687677';
>>>>
>>>>What doesn't work (returns an empty set):
>>>>select * from users where password=password('abcdefg');
>>>>select * from users where user='test' AND
>>>>password=password('abcdefg');
>>>>
>>>>the password and the encrypted form of it are correct - I created a
>>>>duplicate record to verify them.... So I'm not too sure
>>>>what's going on...
>>>>
>>>>Any and all help is appreciated :)
>>>>-K
>>>>
>>>>
>>>>
>>>>
>>>>------------------------------------------------------------
>>>>----------
>>>>
>>>>Subject: RE: ADV_Mail (CH15)
>>>>From: "Darren Spink" <dvs1@b...>
>>>>Date: Sat, 19 Oct 2002 10:05:33 +0100
>>>>X-Message-Number: 4
>>>>
>>>>Thanks for the suggestion Carl, but that just gives the
>>>>same result.  79
>>>>bytes of a 100k attachment sent.
>>>>
>>>>Anyone ??
>>>>
>>>>Regards
>>>>
>>>>
>>>>Darren Spink
>>>>
>>>>TEL: +44(0)113 253 4750
>>>>FAX: +44(0)113 253 1686
>>>>EML: dvs@a...
>>>>ICQ: 56667649
>>>>
>>>>-----Original Message-----
>>>>From: Gellings, C.O. [mailto:gellingsco@p...]
>>>>Sent: 19 October 2002 00:34
>>>>To: beginning php
>>>>Subject: [beginning_php] RE: ADV_Mail (CH15)
>>>>
>>>>
>>>>you could try fopen(...., "r+");
>>>>
>>>>mth Carl
>>>>
>>>>-----Original Message-----
>>>>From: Darren Spink [mailto:dvs1@b...]
>>>>Sent: 18 October 2002 19:35
>>>>To: beginning php
>>>>Subject: [beginning_php] ADV_Mail (CH15)
>>>>
>>>>
>>>>Hi everyone,
>>>>
>>>>A little help if you could spare the time.  I have been
>>>>trying to get the
>>>>adv_mail program from Ch15 working.  Unfortunately when I
>>>>try to run it from
>>>>my server space I get the following 3 warnings
>>>>
>>>>Warning open_basedir restriction in effect.  File in wrong
>>>>directory.....
>>>>Line 186
>>>>
>>>>Warning fopen("/tmp/php1Na6ng","r") - operation not
>>>>permitted....  Line 186
>>>>
>>>>Warning supplied argument is not a valid File-Handle
>>>>resource....  Line 187
>>>>
>>>>Lines 186 and 187 are below:
>>>>      $fp = fopen($userfile, "r");
>>>>      $file = fread($fp, filesize($userfile));
>>>>
>>>>What I am guessing (maybe I am wrong) is it can't create
>>>>the temp file and
>>>>therefore fails on the open and file handle.  There is a
>>>>directory called
>>>>/tmp in the /httpdocs folder (where the PHP is) and from
>>>>what I can tell the
>>>>permissions are correct.
>>>>
>>>>What I am thinking is....if the problem is because of the
>>>>/tmp folder then
>>>>can I specify a different folder ?  if so how ??
>>>>
>>>>Any help/advice solutions would be welcomed.
>>>>
>>>>Regards
>>>>
>>>>
>>>>Darren
>>>>
>>>>Code
>>>>====
>>>>
>>>><?php
>>>>//adv_mailer.php
>>>>
>>>>function mailer_header()
>>>>{
>>>>?>
>>>><HTML>
>>>><HEAD><TITLE>E-mailer</TITLE></HEAD>
>>>><BODY>
>>>><?php
>>>>}
>>>>
>>>>function mailer_footer()
>>>>{
>>>>?>
>>>>
>>>>
>>>></BODY>
>>>></HTML>
>>>><?php
>>>>}
>>>>
>>>>function error_message($msg)
>>>>{
>>>>   mailer_header();
>>>>   echo "<SCRIPT>alert(\"Error: $msg\");history.go(-1)</SCRIPT>";
>>>>   mailer_footer();
>>>>   exit;
>>>>}
>>>>
>>>>function user_message($msg)
>>>>{
>>>>   mailer_header();
>>>>   echo "<SCRIPT>alert(\"$msg\");history.go(-1)</SCRIPT>";
>>>>   mailer_footer();
>>>>   exit;
>>>>}
>>>>
>>>>function mail_form() {
>>>>   global $PHP_SELF;
>>>>?>
>>>><FORM METHOD="POST" ENCTYPE="MULTIPART/FORM-DATA" ACTION="<?php echo
>>>>$PHP_SELF ?>">
>>>><INPUT TYPE="HIDDEN" NAME="action" VALUE="send_mail">
>>>><DIV ALIGN="CENTER ">
>>>><TABLE CELLSPACING="2" CELLPADDING="5" WIDTH="90%" BORDER="1">
>>>>   <TR>
>>>>      <TH ALIGN="CENTER" WIDTH="30%">To</TH>
>>>>      <TD WIDTH="70%"><INPUT NAME="mail_to" SIZE="20"></TD>
>>>>   </TR>
>>>>   <TR>
>>>>      <TH ALIGN="CENTER" WIDTH="30%">Cc</TH>
>>>>      <TD WIDTH="70%"><INPUT NAME="mail_cc" SIZE="20"></TD>
>>>>   </TR>
>>>>   <TR>
>>>>      <TH ALIGN="CENTER" WIDTH="30%">Bcc</TH>
>>>>      <TD WIDTH="70%"><INPUT NAME="mail_bcc" SIZE="20"></TD>
>>>>   </TR>
>>>>   <TR>
>>>>      <TH ALIGN="CENTER" WIDTH="30%">From</TH>
>>>>      <TD WIDTH="70%"><INPUT SIZE="20" NAME="mail_from"></TD>
>>>>   </TR>
>>>>   <TR>
>>>>      <TH ALIGN="CENTER" WIDTH="30%">Reply-to</TH>
>>>>      <TD WIDTH="70%"><INPUT SIZE="20" NAME="mail_reply_to"></TD>
>>>>   </TR>
>>>>   <TR>
>>>>      <TH ALIGN="CENTER" WIDTH="30%">Attachment</TH>
>>>>      <TD WIDTH="70%"><INPUT TYPE="FILE" NAME="userfile"></TD>
>>>>   </TR>
>>>>   <TR>
>>>>      <TH ALIGN="CENTER" WIDTH="30%">Type</TH>
>>>>      <TD WIDTH="70%">
>>>>      <INPUT TYPE="RADIO" VALUE="text" NAME="mail_type" CHECKED>TEXT
>>>>      <INPUT TYPE="RADIO" VALUE="html" NAME="mail_type">HTML</TD>
>>>>   </TR>
>>>>   <TR>
>>>>      <TH ALIGN="CENTER" WIDTH="30%">Encoding</TH>
>>>>      <TD WIDTH="70%">
>>>>      <INPUT TYPE="RADIO" VALUE="7bit" NAME="mail_encoding"
>>>>CHECKED>7BIT
>>>>      <INPUT TYPE="RADIO" VALUE="8bit"
>>>>NAME="mail_encoding">8BIT</TD>
>>>>   </TR>
>>>>   <TR>
>>>>      <TH ALIGN="CENTER" WIDTH="30%">Character Set</TH>
>>>>      <TD WIDTH="70%">
>>>>      <INPUT TYPE="RADIO" VALUE="us-ascii" NAME="mail_charset"
>>>>CHECKED>US-ASCII
>>>>      <INPUT TYPE="RADIO" VALUE="euc-kr"
>>>>NAME="mail_charset">EUC-KR</TD>
>>>>   </TR>
>>>>   <TR>
>>>>      <TH ALIGN="CENTER" WIDTH="30%">Subject</TH>
>>>>      <TD WIDTH="70%"><INPUT SIZE="40" NAME="mail_subject"></TD>
>>>>   </TR>
>>>>   <TR>
>>>>      <TH ALIGN="CENTER" WIDTH="30%">Body</TH>
>>>>      <TD WIDTH="70%"><TEXTAREA NAME="mail_body" ROWS="16"
>>>>         COLS="70"></TEXTAREA></TD>
>>>>   </TR>
>>>>   <TR>
>>>>      <TH WIDTH="100%" COLSPAN="2" ALIGN="CENTER">
>>>>         <INPUT TYPE="SUBMIT" VALUE="Send" NAME="SUBMIT">
>>>>         <INPUT TYPE="RESET" VALUE="Reset" NAME="RESET">
>>>>      </TH>
>>>>   </TR>
>>>></TABLE>
>>>></DIV>
>>>></FORM>
>>>><?php
>>>>}
>>>>
>>>>function send_mail()
>>>>{
>>>>   global $mail_to, $mail_cc, $mail_bcc, $mail_from, $mail_reply_to;
>>>>   global $mail_body, $mail_subject;
>>>>   global $userfile, $userfile_type, $userfile_name, $userfile_size;
>>>>   global $mail_type, $mail_charset, $mail_encoding;
>>>>
>>>>   $mail_parts["mail_type"] = $mail_type;
>>>>   $mail_parts["mail_charset"] = $mail_charset;
>>>>   $mail_parts["mail_encoding"] = $mail_encoding;
>>>>
>>>>   $mail_parts["userfile"] = $userfile;
>>>>   $mail_parts["userfile_type"] = $userfile_type;
>>>>   $mail_parts["userfile_name"] = $userfile_name;
>>>>   $mail_parts["userfile_size"] = $userfile_size;
>>>>
>>>>
>>>>   $mail_parts["mail_to"] = $mail_to;
>>>>   $mail_parts["mail_from"] = $mail_from;
>>>>   $mail_parts["mail_reply_to"] = $mail_reply_to;
>>>>   $mail_parts["mail_cc"] = $mail_cc;
>>>>   $mail_parts["mail_bcc"] = $mail_bcc;
>>>>   $mail_parts["mail_subject"] = trim($mail_subject);
>>>>   $mail_parts["mail_body"] = $mail_body;
>>>>
>>>>   if(my_mail($mail_parts))
>>>>      user_message("Successfully sent an e-mail titled
>>>>'$mail_subject'.");
>>>>
>>>>   else error_message("An unknown error occurred while attempting to
>>>>                                 send an e-mail titled
>>>>'$mail_subject'.");
>>>>}
>>>>
>>>>function my_mail($mail_parts)
>>>>{
>>>>   $mail_to = $mail_parts["mail_to"];
>>>>   $mail_from = $mail_parts["mail_from"];
>>>>   $mail_reply_to = $mail_parts["mail_reply_to"];
>>>>   $mail_cc = $mail_parts["mail_cc"];
>>>>   $mail_bcc = $mail_parts["mail_bcc"];
>>>>   $mail_subject = $mail_parts["mail_subject"];
>>>>   $mail_body = $mail_parts["mail_body"];
>>>>
>>>>   $mail_type = $mail_parts["mail_type"];
>>>>   $mail_charset = $mail_parts["mail_charset"];
>>>>   $mail_encoding = $mail_parts["mail_encoding"];
>>>>
>>>>   $userfile = $mail_parts["userfile"];
>>>>   $userfile_type = $mail_parts["userfile_type"];
>>>>   $userfile_name = $mail_parts["userfile_name"];
>>>>   echo "userfile_name = ".$userfile_name."\n";
>>>>   $userfile_size = $mail_parts["userfile_size"];
>>>>
>>>>   if(empty($mail_to)) error_message("Empty to field!");
>>>>   if(empty($mail_subject)) error_message("Empty subject!");
>>>>   if(empty($mail_body)) error_message("Empty body! ");
>>>>
>>>>   $mail_to = str_replace(";", ",", $mail_to);
>>>>
>>>>   $mail_headers = '';
>>>>
>>>>   if(!empty($mail_from)) $mail_headers .= "From: $mail_from\n";
>>>>   if(!empty($mail_reply_to)) $mail_headers .= "Reply-to:
>>>>$mail_reply_to\n";
>>>>   if(!empty($mail_cc))
>>>>            $mail_headers .= "Cc: " . str_replace(";", ",",
>>>>$mail_cc) .
>>>>"\n";
>>>>   if(!empty($mail_bcc))
>>>>            $mail_headers .= "Bcc: " . str_replace(";",
>>>>",", $mail_bcc) .
>>>>"\n";
>>>>
>>>>   $mail_subject = stripslashes($mail_subject);
>>>>   $mail_body = stripslashes($mail_body);
>>>>
>>>>   if($userfile_size > 0)
>>>>   {
>>>>      $mail_boundary = md5(uniqid(time()));
>>>>      $mail_headers .= "MIME-Version: 1.0\r\n";
>>>>      $mail_headers .= "Content-type: multipart/mixed;
>>>>
>>>>boundary=\"$mail_boundary\"\r\n\r\n";
>>>>      $mail_headers .= "This is a multi-part message in MIME
>>>>format.\r\n\r\n";
>>>>
>>>>	echo "userfile".$userfile."\n";
>>>>      $fp = fopen($userfile, "r");
>>>>      $file = fread($fp, filesize($userfile));
>>>>      $file = chunk_split(base64_encode($file));
>>>>
>>>>      $new_mail_body = "--$mail_boundary\r\n";
>>>>      $new_mail_body .
>>>>"Content-type:text/plain;charset=$mail_charset\r\n";
>>>>      $new_mail_body .
>>>>"Content-transfer-encoding:$mail_encoding\r\n\r\n";
>>>>      $new_mail_body .= "$mail_body\r\n";
>>>>      $new_mail_body .= "--$mail_boundary\r\n";
>>>>      if(!empty($userfile_type)) $mime_type = $userfile_type;
>>>>      else $mime_type = "application/octet-stream";
>>>>
>>>>      $new_mail_body .
>>>>"Content-type:$mime_type;name=$userfile_name\r\n";
>>>>      $new_mail_body .= "Content-transfer-encoding:base64\r\n\r\n";
>>>>      $new_mail_body .= $file . "\r\n\r\n";
>>>>      $new_mail_body .= "--$mail_boundary--";
>>>>      $mail_body = $new_mail_body;
>>>>   }
>>>>   else if($mail_type == 'html')
>>>>   {
>>>>      $mail_headers .= "Content-type: text/html;
>>>>charset=$mail_charset\r\n";
>>>>      $mail_headers .
>>>>"Content-transfer-encoding:$mail_encoding\r\n\r\n";
>>>>   }
>>>>   else
>>>>   {
>>>>      $mail_headers .= "Content-type: text/plain;
>>>>charset=$mail_charset\r\n";
>>>>      $mail_headers .
>>>>"Content-transfer-encoding:$mail_encoding\r\n\r\n";
>>>>   }
>>>>
>>>>   return mail($mail_to,$mail_subject,$mail_body,$mail_headers);
>>>>}
>>>>
>>>>switch ($action)
>>>>{
>>>>   case "send_mail":
>>>>      mailer_header();
>>>>      send_mail();
>>>>      mailer_footer();
>>>>      break;
>>>>   case "mail_form":
>>>>      mailer_header();
>>>>      mail_form();
>>>>      mailer_footer();
>>>>      break;
>>>>   default:
>>>>      mailer_header();
>>>>      mail_form();
>>>>      mailer_footer();
>>>>      break;
>>>>}
>>>>?>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>------------------------------------------------------------
>>>>----------
>>>>
>>>>Subject: RE: ADV_Mail (CH15)
>>>>From: "Gellings, C.O." <gellingsco@p...>
>>>>Date: Sat, 19 Oct 2002 14:59:37 +0200
>>>>X-Message-Number: 5
>>>>
>>>>How are the read / write / exexute set for that directory?? (CHMOD)
>>>>
>>>>-----Original Message-----
>>>>From: Darren Spink [mailto:dvs1@b...]
>>>>Sent: 19 October 2002 11:06
>>>>To: beginning php
>>>>Subject: [beginning_php] RE: ADV_Mail (CH15)
>>>>
>>>>
>>>>Thanks for the suggestion Carl, but that just gives the
>>>>same result.  79
>>>>bytes of a 100k attachment sent.
>>>>
>>>>Anyone ??
>>>>
>>>>Regards
>>>>
>>>>
>>>>Darren Spink
>>>>
>>>>TEL: +44(0)113 253 4750
>>>>FAX: +44(0)113 253 1686
>>>>EML: dvs@a...
>>>>ICQ: 56667649
>>>>
>>>>-----Original Message-----
>>>>From: Gellings, C.O. [mailto:gellingsco@p...]
>>>>Sent: 19 October 2002 00:34
>>>>To: beginning php
>>>>Subject: [beginning_php] RE: ADV_Mail (CH15)
>>>>
>>>>
>>>>you could try fopen(...., "r+");
>>>>
>>>>mth Carl
>>>>
>>>>-----Original Message-----
>>>>From: Darren Spink [mailto:dvs1@b...]
>>>>Sent: 18 October 2002 19:35
>>>>To: beginning php
>>>>Subject: [beginning_php] ADV_Mail (CH15)
>>>>
>>>>
>>>>Hi everyone,
>>>>
>>>>A little help if you could spare the time.  I have been
>>>>trying to get the
>>>>adv_mail program from Ch15 working.  Unfortunately when I
>>>>try to run it from
>>>>my server space I get the following 3 warnings
>>>>
>>>>Warning open_basedir restriction in effect.  File in wrong
>>>>directory.....
>>>>Line 186
>>>>
>>>>Warning fopen("/tmp/php1Na6ng","r") - operation not
>>>>permitted....  Line 186
>>>>
>>>>Warning supplied argument is not a valid File-Handle
>>>>resource....  Line 187
>>>>
>>>>Lines 186 and 187 are below:
>>>>      $fp = fopen($userfile, "r");
>>>>      $file = fread($fp, filesize($userfile));
>>>>
>>>>What I am guessing (maybe I am wrong) is it can't create
>>>>the temp file and
>>>>therefore fails on the open and file handle.  There is a
>>>>directory called
>>>>/tmp in the /httpdocs folder (where the PHP is) and from
>>>>what I can tell the
>>>>permissions are correct.
>>>>
>>>>What I am thinking is....if the problem is because of the
>>>>/tmp folder then
>>>>can I specify a different folder ?  if so how ??
>>>>
>>>>Any help/advice solutions would be welcomed.
>>>>
>>>>Regards
>>>>
>>>>
>>>>Darren
>>>>
>>>>Code
>>>>====
>>>>
>>>><?php
>>>>//adv_mailer.php
>>>>
>>>>function mailer_header()
>>>>{
>>>>?>
>>>><HTML>
>>>><HEAD><TITLE>E-mailer</TITLE></HEAD>
>>>><BODY>
>>>><?php
>>>>}
>>>>
>>>>function mailer_footer()
>>>>{
>>>>?>
>>>>
>>>>
>>>>
>>>></BODY>
>>>></HTML>
>>>><?php
>>>>}
>>>>
>>>>function error_message($msg)
>>>>{
>>>>   mailer_header();
>>>>   echo "<SCRIPT>alert(\"Error: $msg\");history.go(-1)</SCRIPT>";
>>>>   mailer_footer();
>>>>   exit;
>>>>}
>>>>
>>>>function user_message($msg)
>>>>{
>>>>   mailer_header();
>>>>   echo "<SCRIPT>alert(\"$msg\");history.go(-1)</SCRIPT>";
>>>>   mailer_footer();
>>>>   exit;
>>>>}
>>>>
>>>>function mail_form() {
>>>>   global $PHP_SELF;
>>>>?>
>>>><FORM METHOD="POST" ENCTYPE="MULTIPART/FORM-DATA" ACTION="<?php echo
>>>>$PHP_SELF ?>">
>>>><INPUT TYPE="HIDDEN" NAME="action" VALUE="send_mail">
>>>><DIV ALIGN="CENTER ">
>>>><TABLE CELLSPACING="2" CELLPADDING="5" WIDTH="90%" BORDER="1">
>>>>   <TR>
>>>>      <TH ALIGN="CENTER" WIDTH="30%">To</TH>
>>>>      <TD WIDTH="70%"><INPUT NAME="mail_to" SIZE="20"></TD>
>>>>   </TR>
>>>>   <TR>
>>>>      <TH ALIGN="CENTER" WIDTH="30%">Cc</TH>
>>>>      <TD WIDTH="70%"><INPUT NAME="mail_cc" SIZE="20"></TD>
>>>>   </TR>
>>>>   <TR>
>>>>      <TH ALIGN="CENTER" WIDTH="30%">Bcc</TH>
>>>>      <TD WIDTH="70%"><INPUT NAME="mail_bcc" SIZE="20"></TD>
>>>>   </TR>
>>>>   <TR>
>>>>      <TH ALIGN="CENTER" WIDTH="30%">From</TH>
>>>>      <TD WIDTH="70%"><INPUT SIZE="20" NAME="mail_from"></TD>
>>>>   </TR>
>>>>   <TR>
>>>>      <TH ALIGN="CENTER" WIDTH="30%">Reply-to</TH>
>>>>      <TD WIDTH="70%"><INPUT SIZE="20" NAME="mail_reply_to"></TD>
>>>>   </TR>
>>>>   <TR>
>>>>      <TH ALIGN="CENTER" WIDTH="30%">Attachment</TH>
>>>>      <TD WIDTH="70%"><INPUT TYPE="FILE" NAME="userfile"></TD>
>>>>   </TR>
>>>>   <TR>
>>>>      <TH ALIGN="CENTER" WIDTH="30%">Type</TH>
>>>>      <TD WIDTH="70%">
>>>>      <INPUT TYPE="RADIO" VALUE="text" NAME="mail_type" CHECKED>TEXT
>>>>      <INPUT TYPE="RADIO" VALUE="html" NAME="mail_type">HTML</TD>
>>>>   </TR>
>>>>   <TR>
>>>>      <TH ALIGN="CENTER" WIDTH="30%">Encoding</TH>
>>>>      <TD WIDTH="70%">
>>>>      <INPUT TYPE="RADIO" VALUE="7bit" NAME="mail_encoding"
>>>>CHECKED>7BIT
>>>>      <INPUT TYPE="RADIO" VALUE="8bit"
>>>>NAME="mail_encoding">8BIT</TD>
>>>>   </TR>
>>>>   <TR>
>>>>      <TH ALIGN="CENTER" WIDTH="30%">Character Set</TH>
>>>>      <TD WIDTH="70%">
>>>>      <INPUT TYPE="RADIO" VALUE="us-ascii" NAME="mail_charset"
>>>>CHECKED>US-ASCII
>>>>      <INPUT TYPE="RADIO" VALUE="euc-kr"
>>>>NAME="mail_charset">EUC-KR</TD>
>>>>   </TR>
>>>>   <TR>
>>>>      <TH ALIGN="CENTER" WIDTH="30%">Subject</TH>
>>>>      <TD WIDTH="70%"><INPUT SIZE="40" NAME="mail_subject"></TD>
>>>>   </TR>
>>>>   <TR>
>>>>      <TH ALIGN="CENTER" WIDTH="30%">Body</TH>
>>>>      <TD WIDTH="70%"><TEXTAREA NAME="mail_body" ROWS="16"
>>>>         COLS="70"></TEXTAREA></TD>
>>>>   </TR>
>>>>   <TR>
>>>>      <TH WIDTH="100%" COLSPAN="2" ALIGN="CENTER">
>>>>         <INPUT TYPE="SUBMIT" VALUE="Send" NAME="SUBMIT">
>>>>         <INPUT TYPE="RESET" VALUE="Reset" NAME="RESET">
>>>>      </TH>
>>>>   </TR>
>>>></TABLE>
>>>></DIV>
>>>></FORM>
>>>><?php
>>>>}
>>>>
>>>>function send_mail()
>>>>{
>>>>   global $mail_to, $mail_cc, $mail_bcc, $mail_from, $mail_reply_to;
>>>>   global $mail_body, $mail_subject;
>>>>   global $userfile, $userfile_type, $userfile_name, $userfile_size;
>>>>   global $mail_type, $mail_charset, $mail_encoding;
>>>>
>>>>   $mail_parts["mail_type"] = $mail_type;
>>>>   $mail_parts["mail_charset"] = $mail_charset;
>>>>   $mail_parts["mail_encoding"] = $mail_encoding;
>>>>
>>>>   $mail_parts["userfile"] = $userfile;
>>>>   $mail_parts["userfile_type"] = $userfile_type;
>>>>   $mail_parts["userfile_name"] = $userfile_name;
>>>>   $mail_parts["userfile_size"] = $userfile_size;
>>>>
>>>>
>>>>   $mail_parts["mail_to"] = $mail_to;
>>>>   $mail_parts["mail_from"] = $mail_from;
>>>>   $mail_parts["mail_reply_to"] = $mail_reply_to;
>>>>   $mail_parts["mail_cc"] = $mail_cc;
>>>>   $mail_parts["mail_bcc"] = $mail_bcc;
>>>>   $mail_parts["mail_subject"] = trim($mail_subject);
>>>>   $mail_parts["mail_body"] = $mail_body;
>>>>
>>>>   if(my_mail($mail_parts))
>>>>      user_message("Successfully sent an e-mail titled
>>>>'$mail_subject'.");
>>>>
>>>>   else error_message("An unknown error occurred while attempting to
>>>>                                 send an e-mail titled
>>>>'$mail_subject'.");
>>>>}
>>>>
>>>>function my_mail($mail_parts)
>>>>{
>>>>   $mail_to = $mail_parts["mail_to"];
>>>>   $mail_from = $mail_parts["mail_from"];
>>>>   $mail_reply_to = $mail_parts["mail_reply_to"];
>>>>   $mail_cc = $mail_parts["mail_cc"];
>>>>   $mail_bcc = $mail_parts["mail_bcc"];
>>>>   $mail_subject = $mail_parts["mail_subject"];
>>>>   $mail_body = $mail_parts["mail_body"];
>>>>
>>>>   $mail_type = $mail_parts["mail_type"];
>>>>   $mail_charset = $mail_parts["mail_charset"];
>>>>   $mail_encoding = $mail_parts["mail_encoding"];
>>>>
>>>>   $userfile = $mail_parts["userfile"];
>>>>   $userfile_type = $mail_parts["userfile_type"];
>>>>   $userfile_name = $mail_parts["userfile_name"];
>>>>   echo "userfile_name = ".$userfile_name."\n";
>>>>   $userfile_size = $mail_parts["userfile_size"];
>>>>
>>>>   if(empty($mail_to)) error_message("Empty to field!");
>>>>   if(empty($mail_subject)) error_message("Empty subject!");
>>>>   if(empty($mail_body)) error_message("Empty body! ");
>>>>
>>>>   $mail_to = str_replace(";", ",", $mail_to);
>>>>
>>>>   $mail_headers = '';
>>>>
>>>>   if(!empty($mail_from)) $mail_headers .= "From: $mail_from\n";
>>>>   if(!empty($mail_reply_to)) $mail_headers .= "Reply-to:
>>>>$mail_reply_to\n";
>>>>   if(!empty($mail_cc))
>>>>            $mail_headers .= "Cc: " . str_replace(";", ",",
>>>>$mail_cc) .
>>>>"\n";
>>>>   if(!empty($mail_bcc))
>>>>            $mail_headers .= "Bcc: " . str_replace(";",
>>>>",", $mail_bcc) .
>>>>"\n";
>>>>
>>>>   $mail_subject = stripslashes($mail_subject);
>>>>   $mail_body = stripslashes($mail_body);
>>>>
>>>>   if($userfile_size > 0)
>>>>   {
>>>>      $mail_boundary = md5(uniqid(time()));
>>>>      $mail_headers .= "MIME-Version: 1.0\r\n";
>>>>      $mail_headers .= "Content-type: multipart/mixed;
>>>>
>>>>boundary=\"$mail_boundary\"\r\n\r\n";
>>>>      $mail_headers .= "This is a multi-part message in MIME
>>>>format.\r\n\r\n";
>>>>
>>>>	echo "userfile".$userfile."\n";
>>>>      $fp = fopen($userfile, "r");
>>>>      $file = fread($fp, filesize($userfile));
>>>>      $file = chunk_split(base64_encode($file));
>>>>
>>>>      $new_mail_body = "--$mail_boundary\r\n";
>>>>      $new_mail_body .
>>>>"Content-type:text/plain;charset=$mail_charset\r\n";
>>>>      $new_mail_body .
>>>>"Content-transfer-encoding:$mail_encoding\r\n\r\n";
>>>>      $new_mail_body .= "$mail_body\r\n";
>>>>      $new_mail_body .= "--$mail_boundary\r\n";
>>>>      if(!empty($userfile_type)) $mime_type = $userfile_type;
>>>>      else $mime_type = "application/octet-stream";
>>>>
>>>>      $new_mail_body .
>>>>"Content-type:$mime_type;name=$userfile_name\r\n";
>>>>      $new_mail_body .= "Content-transfer-encoding:base64\r\n\r\n";
>>>>      $new_mail_body .= $file . "\r\n\r\n";
>>>>      $new_mail_body .= "--$mail_boundary--";
>>>>      $mail_body = $new_mail_body;
>>>>   }
>>>>   else if($mail_type == 'html')
>>>>   {
>>>>      $mail_headers .= "Content-type: text/html;
>>>>charset=$mail_charset\r\n";
>>>>      $mail_headers .
>>>>"Content-transfer-encoding:$mail_encoding\r\n\r\n";
>>>>   }
>>>>   else
>>>>   {
>>>>      $mail_headers .= "Content-type: text/plain;
>>>>charset=$mail_charset\r\n";
>>>>      $mail_headers .
>>>>"Content-transfer-encoding:$mail_encoding\r\n\r\n";
>>>>   }
>>>>
>>>>   return mail($mail_to,$mail_subject,$mail_body,$mail_headers);
>>>>}
>>>>
>>>>switch ($action)
>>>>{
>>>>   case "send_mail":
>>>>      mailer_header();
>>>>      send_mail();
>>>>      mailer_footer();
>>>>      break;
>>>>   case "mail_form":
>>>>      mailer_header();
>>>>      mail_form();
>>>>      mailer_footer();
>>>>      break;
>>>>   default:
>>>>      mailer_header();
>>>>      mail_form();
>>>>      mailer_footer();
>>>>      break;
>>>>}
>>>>?>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>------------------------------------------------------------
>>>>----------
>>>>
>>>>Subject: Re: Login Script...
>>>>From: "Trey Carroll" <treycarroll@y...>
>>>>Date: Sat, 19 Oct 2002 22:55:00
>>>>X-Message-Number: 6
>>>>
>>>>Looks like you are asking for the row where password is
>>>>abcdefg, instead
>>>>of 8687677.
>>>>
>>>>Did you mean:
>>>>select * from users where user='test' AND
>>>>password=password('8687677');
>>>>?
>>>>
>>>>> Hi,
>>>>	I'm just having some trouble with authenticating usernames...
>>>>Here's how it
>>>>is right now...
>>>>
>>>>username=test
>>>>password=abcdefg
>>>>encrypted password in mySQL = 8687677
>>>>
>>>>What works:
>>>>select * from users where user='test';
>>>>select * from users where password='8687677';
>>>>select * from users where user='test' AND password='8687677';
>>>>
>>>>What doesn't work (returns an empty set):
>>>>select * from users where password=password('abcdefg');
>>>>select * from users where user='test' AND
>>>>password=password('abcdefg');
>>>>
>>>>the password and the encrypted form of it are correct - I created a
>>>>duplicate record to verify them.... So I'm not too sure
>>>>what's going on...
>>>>
>>>>Any and all help is appreciated :)
>>>>-K



Message #4 by "KayKay-GG \(E-mail\)" <kaykay@g...> on Mon, 21 Oct 2002 22:55:33 +0530
Fixed! thanks to Joe. It was because of the size of my password field :)
-K

>>>>-----Original Message-----
>>>>From: KayKay [mailto:kkumar@b...]On Behalf Of 
>>>>KayKay-GG (E-mail)
>>>>Sent: 21 October 2002 11:02
>>>>To: beginning php
>>>>Cc: PHP (E-mail)
>>>>Subject: [beginning_php] RE: Login Script...
>>>>
>>>>
>>>>Hey Joe ;)
>>>>	Thanks for the reply. The password() function is not a 
>>>>PHP function - it's
>>>>a MySQL function, which is probably why you can't find any 
>>>>references to it
>>>>in PHP manuals :)
>>>>	The password() function (on testing) returns the same 
>>>>value for the same
>>>>string - password('abcdefg') will always return the same 
>>>>string - so to
>>>>compare passwords, you will be doing something like this:
>>>>
>>>>if (password($entered_password) == $stored_password)
>>>>
>>>>You get $stored_password from a MySQL query.
>>>>
>>>>BTW This is how it's explained in the book as well - so I 
>>>>don't know why it
>>>>doesn't seem to be working for me :(
>>>>
>>>>Thanks mate,
>>>>-K
>>>>P.S I'm cc:ing this to the mailing list as well :)
>>>>
>>>>>>>>-----Original Message-----
>>>>>>>>From: BTS Technologies, Ltd. [mailto:sureshot@c...]
>>>>>>>>Sent: 21 October 2002 11:44
>>>>>>>>To: kaykay@g...
>>>>>>>>Subject: FW: beginning_php digest: October 19, 2002
>>>>>>>>
>>>>>>>>
>>>>>>>>Hi KayKay,
>>>>>>>>
>>>>>>>>I'm not familiar with the password() function off hand, but
>>>>>>>>I ran into a
>>>>>>>>similar problem on a java project.  It turned out that 
>>>>the password
>>>>>>>>encryption function used the userID as well as the
>>>>>>>>password.  When we
>>>>>>>>encrypted a default password for all users of "password4u"
>>>>>>>>it was different
>>>>>>>>from when each user encrypted the password since it used
>>>>>>>>the userID in the
>>>>>>>>encryption process - giving different encrypted strings for
>>>>>>>>each user even
>>>>>>>>though the password was the same.
>>>>>>>>
>>>>>>>>I didn't see anything in the PHP docs on a password()
>>>>>>>>function.  Is it
>>>>>>>>something you (or someone else) has written?
>>>>>>>>
>>>>>>>>Let me know if this helps.
>>>>>>>>
>>>>>>>>Joe




  Return to Index