General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 15th, 2003, 10:38 PM
frankie frankie is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 1 frankie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
need help create a loop here

this program that i want to modify now searchases the table customers for a matching email and if the match is made it checks for the password if the password fails it gives a login fail and if matches then it logs the customer in, i need it modified to do these
check for the matching email after the match is made compare the password if the password matches then login the customer if the match fails it should continue searching the db for another email match and continue this process untill either a match is made or no more customers.
i am very very new and rally know nothing about php and mysql and would really appreciate any help you can provide


<?php
/*
$Id: login.php,v 1.75 2003/02/13 03:01:49 hpdl Exp $

osCommerce, Open Source E-Commerce Solutions
URL

Copyright (c) 2003 osCommerce

Released under the GNU General Public License
*/

require('includes/application_top.php');

if (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'process')) {
$email_address = tep_db_prepare_input($HTTP_POST_VARS['email_address']);
$password = tep_db_prepare_input($HTTP_POST_VARS['password']);
///////////i think the search starts here
// Check if email exists
$check_customer_query = tep_db_query("select customers_id, customers_firstname, customers_password, customers_email_address, customers_default_address_id from " . TABLE_CUSTOMERS . " where customers_email_address = '" . tep_db_input($email_address) . "'");
if (!tep_db_num_rows($check_customer_query)) {
$HTTP_GET_VARS['login'] = 'fail';
} else {
$check_customer = tep_db_fetch_array($check_customer_query);
// Check that password is good
if (!tep_validate_password($password, $check_customer['customers_password'])) {
$HTTP_GET_VARS['login'] = 'fail';
} else {
$check_country_query = tep_db_query("select entry_country_id, entry_zone_id from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . $check_customer['customers_id'] . "' and address_book_id = '1'");
$check_country = tep_db_fetch_array($check_country_query);

$customer_id = $check_customer['customers_id'];
$customer_default_address_id = $check_customer['customers_default_address_id'];
$customer_first_name = $check_customer['customers_firstname'];
$customer_country_id = $check_country['entry_country_id'];
$customer_zone_id = $check_country['entry_zone_id'];
tep_session_register('customer_id');
tep_session_register('customer_default_address_id' );
tep_session_register('customer_first_name');
tep_session_register('customer_country_id');
tep_session_register('customer_zone_id');

$date_now = date('Ymd');
tep_db_query("update " . TABLE_CUSTOMERS_INFO . " set customers_info_date_of_last_logon = now(), customers_info_number_of_logons = customers_info_number_of_logons+1 where customers_info_id = '" . $customer_id . "'");

// restore cart contents
$cart->restore_contents();

if (sizeof($navigation->snapshot) > 0) {
$origin_href = tep_href_link($navigation->snapshot['page'], tep_array_to_string($navigation->snapshot['get'], array(tep_session_name())), $navigation->snapshot['mode']);
$navigation->clear_snapshot();
tep_redirect($origin_href);
} else {
tep_redirect(tep_href_link(FILENAME_DEFAULT));
}
}
}
}

require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_LOGIN);

$breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_LOGIN, '', 'SSL'));
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<script language="javascript"><!--
function session_win() {
window.open("<?php echo tep_href_link(FILENAME_INFO_SHOPPING_CART); ?>","info_shopping_cart","height=460,width=430,toolbar=no,statusbar=no,scrol lbars=yes").focus();
}
//--></script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="3" cellpadding="3">
<tr>
<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
</table></td>
<!-- body_text //-->
<td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td><table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
<td rowspan="2" class="pageHeading" align="right"><?php echo tep_image(DIR_WS_IMAGES . 'table_background_login.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
</tr>
</table></td>
</tr>
<tr>
<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
</tr>
<?php
if (isset($HTTP_GET_VARS['login']) && ($HTTP_GET_VARS['login'] == 'fail')) {
$info_message = TEXT_LOGIN_ERROR;
} elseif ($cart->count_contents()) {
$info_message = TEXT_VISITORS_CART;
}

if (isset($info_message)) {
?>
<tr>
<td class="smallText"><?php echo $info_message; ?></td>
</tr>
<tr>
<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
</tr>
<?php
}
?>
<tr>
<td><?php echo tep_draw_form('login', tep_href_link(FILENAME_LOGIN, 'action=process', 'SSL')); ?><table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr>
<td class="main" width="50%" valign="top"><b><?php echo HEADING_NEW_CUSTOMER; ?></b></td>
<td class="main" width="50%" valign="top"><b><?php echo HEADING_RETURNING_CUSTOMER; ?></b></td>
</tr>
<tr>
<td width="50%" height="100%" valign="top"><table border="0" width="100%" height="100%" cellspacing="0" cellpadding="1" class="infoBox">
<tr>
<td><table border="0" width="100%" height="100%" cellspacing="0" cellpadding="2" class="infoBoxContents">
<tr>
<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
</tr>
<tr>
<td class="main" valign="top"><?php echo TEXT_NEW_CUSTOMER . '<br><br>' . TEXT_NEW_CUSTOMER_INTRODUCTION; ?></td>
</tr>
<tr>
<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
</tr>
</table></td>
</tr>
</table></td>
<td width="50%" height="100%" valign="top"><table border="0" width="100%" height="100%" cellspacing="0" cellpadding="1" class="infoBox">
<tr>
<td><table border="0" width="100%" height="100%" cellspacing="0" cellpadding="2" class="infoBoxContents">
<tr>
<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
</tr>
<tr>
<td class="main" colspan="2"><?php echo TEXT_RETURNING_CUSTOMER; ?></td>
</tr>
<tr>
<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
</tr>
<tr>
<td class="main"><b><?php echo ENTRY_EMAIL_ADDRESS; ?></b></td>
<td class="main"><?php echo tep_draw_input_field('email_address'); ?></td>
</tr>
<tr>
<td class="main"><b><?php echo ENTRY_PASSWORD; ?></b></td>
<td class="main"><?php echo tep_draw_password_field('password'); ?></td>
</tr>
<tr>
<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
</tr>
<tr>
<td class="smallText" colspan="2"><?php echo '<a href="' . tep_href_link(FILENAME_PASSWORD_FORGOTTEN, '', 'SSL') . '">' . TEXT_PASSWORD_FORGOTTEN . '</a>'; ?></td>
</tr>
<tr>
<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td width="50%" align="right" valign="top"><?php echo '<a href="' . tep_href_link(FILENAME_CREATE_ACCOUNT, '', 'SSL') . '">' . tep_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE) . '</a>'; ?></td>
<td width="50%" align="right" valign="top"><?php echo tep_image_submit('button_login.gif', IMAGE_BUTTON_LOGIN); ?></td>
</tr>
</table></form></td>
</tr>
</table></td>
<!-- body_text_eof //-->
<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
cut out some of the end thanks

Reply With Quote
  #2  
Old October 15th, 2003, 11:42 PM
manoloweb manoloweb is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Monterrey MX
Posts: 49 manoloweb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Wow... I guess if someone will read it without colors....

PHP Code:
<?php 
/* 
$Id: login.php,v 1.75 2003/02/13 03:01:49 hpdl Exp $ 

osCommerce, Open Source E-Commerce Solutions 
[url]http://www.oscommerce.com[/url] 

Copyright (c) 2003 osCommerce 

Released under the GNU General Public License 
*/ 

require('includes/application_top.php'); 

if (isset(
$HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'process')) { 
$email_address tep_db_prepare_input($HTTP_POST_VARS['email_addres
s'
]); 
$password tep_db_prepare_input($HTTP_POST_VARS['password']);

///////////i think the search starts here 
// Check if email exists 
$check_customer_query tep_db_query("select customers_id, customers_firstname, customers_password, customers_email_address, customers_default_address_id from " TABLE_CUSTOMERS " where customers_email_address = '" tep_db_input($email_address) . "'"); 
if (!
tep_db_num_rows($check_customer_query)) { 
$HTTP_GET_VARS['login'] = 'fail'
} else { 
$check_customer tep_db_fetch_array($check_customer_query); 
// Check that password is good 
if (!tep_validate_password($password$check_customer['customers_password'])) { 
$HTTP_GET_VARS['login'] = 'fail'
} else { 
$check_country_query tep_db_query("select entry_country_id, entry_zone_id from " TABLE_ADDRESS_BOOK " where customers_id = '" $check_customer['customers_id'] . "' and address_book_id = '1'"); 
$check_country tep_db_fetch_array($check_country_query); 

$customer_id $check_customer['customers_id']; 
$customer_default_address_id $check_customer['customers_default_address_id']; 
$customer_first_name $check_customer['customers_firstname']; 
$customer_country_id $check_country['entry_country_id']; 
$customer_zone_id $check_country['entry_zone_id']; 
tep_session_register('customer_id'); 
tep_session_register('customer_default_address_id'  
); 
tep_session_register('customer_first_name'); 
tep_session_register('customer_country_id'); 
tep_session_register('customer_zone_id'); 

$date_now date('Ymd'); 
tep_db_query("update " TABLE_CUSTOMERS_INFO " set customers_info_date_of_last_logon = now(), customers_info_number_of_logons = customers_info_number_of_logons+1 where customers_info_id = '" $customer_id "'"); 

// restore cart contents 
$cart->restore_contents(); 

if (
sizeof($navigation->snapshot) > 0) { 
$origin_href tep_href_link($navigation->snapshot['page'], tep_array_to_string($navigation->snapshot['get'], array(tep_session_name())), $navigation->snapshot['mode']); 
$navigation->clear_snapshot(); 
tep_redirect($origin_href); 
} else { 
tep_redirect(tep_href_link(FILENAME_DEFAULT)); 





require(
DIR_WS_LANGUAGES $language '/' FILENAME_LOGIN); 

$breadcrumb->add(NAVBAR_TITLEtep_href_link(FILENAME_LOGIN'''SSL')); 
?> 
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html <?php echo HTML_PARAMS?>
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET?>"> 
<title><?php echo TITLE?></title> 
<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER HTTP_SERVER) . DIR_WS_CATALOG?>"> 
<link rel="stylesheet" type="text/css" href="stylesheet.css"> 
<script language="javascript"><!-- 
function session_win() { 
window.open("<?php echo tep_href_link(FILENAME_INFO_SHOPPING_CART); ?>","info_shopping_cart"," height=460,width=430,toolbar=no,statusbar=no,scrol  
lbars=yes").focus(); 

//--></script> 
</head> 
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0"> 
<!-- header //--> 
<?php require(DIR_WS_INCLUDES 'header.php'); ?> 
<!-- header_eof //--> 

<!-- body //--> 
<table border="0" width="100%" cellspacing="3" cellpadding="3"> 
<tr> 
<td width="<?php echo BOX_WIDTH?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH?>" cellspacing="0" cellpadding="2"> 
<!-- left_navigation //--> 
<?php require(DIR_WS_INCLUDES 'column_left.php'); ?> 
<!-- left_navigation_eof //--> 
</table></td> 
<!-- body_text //--> 
<td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0"> 
<tr> 
<td><table border="0" width="100%" cellspacing="0" cellpadding="0"> 
<tr> 
<td class="pageHeading"><?php echo HEADING_TITLE?></td> 
<td rowspan="2" class="pageHeading" align="right"><?php echo tep_image(DIR_WS_IMAGES 'table_background_login.gif'HEADING_TITLEHEADING_IMAGE_WIDTHHEADING_IMAGE_HEIGHT); ?></td> 
</tr> 
</table></td> 
</tr> 
<tr> 
<td><?php echo tep_draw_separator('pixel_trans.gif''100%''10'); ?></td> 
</tr> 
<?php 
if (isset($HTTP_GET_VARS['login']) && ($HTTP_GET_VARS['login'] == 'fail')) { 
$info_message TEXT_LOGIN_ERROR
} elseif (
$cart->count_contents()) { 
$info_message TEXT_VISITORS_CART


if (isset(
$info_message)) { 
?> 
<tr> 
<td class="smallText"><?php echo $info_message?></td> 
</tr> 
<tr> 
<td><?php echo tep_draw_separator('pixel_trans.gif''100%''10'); ?></td> 
</tr> 
<?php 

?> 
<tr> 
<td><?php echo tep_draw_form('login'tep_href_link(FILENAME_LOGIN'action=process''SSL')); ?><table border="0" width="100%" cellspacing="0" cellpadding="2"> 
<tr> 
<td class="main" width="50%" valign="top"><b><?php echo HEADING_NEW_CUSTOMER?></b></td> 
<td class="main" width="50%" valign="top"><b><?php echo HEADING_RETURNING_CUSTOMER?></b></td> 
</tr> 
<tr> 
<td width="50%" height="100%" valign="top"><table border="0" width="100%" height="100%" cellspacing="0" cellpadding="1" class="infoBox"> 
<tr> 
<td><table border="0" width="100%" height="100%" cellspacing="0" cellpadding="2" class="infoBoxContents"> 
<tr> 
<td><?php echo tep_draw_separator('pixel_trans.gif''100%''10'); ?></td> 
</tr> 
<tr> 
<td class="main" valign="top"><?php echo TEXT_NEW_CUSTOMER '<br><br>' TEXT_NEW_CUSTOMER_INTRODUCTION?></td> 
</tr> 
<tr> 
<td><?php echo tep_draw_separator('pixel_trans.gif''100%''10'); ?></td> 
</tr> 
</table></td> 
</tr> 
</table></td> 
<td width="50%" height="100%" valign="top"><table border="0" width="100%" height="100%" cellspacing="0" cellpadding="1" class="infoBox"> 
<tr> 
<td><table border="0" width="100%" height="100%" cellspacing="0" cellpadding="2" class="infoBoxContents"> 
<tr> 
<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif''100%''10'); ?></td> 
</tr> 
<tr> 
<td class="main" colspan="2"><?php echo TEXT_RETURNING_CUSTOMER?></td> 
</tr> 
<tr> 
<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif''100%''10'); ?></td> 
</tr> 
<tr> 
<td class="main"><b><?php echo ENTRY_EMAIL_ADDRESS?></b></td> 
<td class="main"><?php echo tep_draw_input_field('email_address'); ?></td> 
</tr> 
<tr> 
<td class="main"><b><?php echo ENTRY_PASSWORD?></b></td> 
<td class="main"><?php echo tep_draw_password_field('password'); ?></td> 
</tr> 
<tr> 
<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif''100%''10'); ?></td> 
</tr> 
<tr> 
<td class="smallText" colspan="2"><?php echo '<a href="' tep_href_link(FILENAME_PASSWORD_FORGOTTEN'''SSL') . '">' TEXT_PASSWORD_FORGOTTEN '</a>'?></td> 
</tr> 
<tr> 
<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif''100%''10'); ?></td> 
</tr> 
</table></td> 
</tr> 
</table></td> 
</tr> 
<tr> 
<td width="50%" align="right" valign="top"><?php echo '<a href="' tep_href_link(FILENAME_CREATE_ACCOUNT'''SSL') . '">' tep_image_button('button_continue.gif'IMAGE_BUTTON_CONTINUE) . '</a>'?></td> 
<td width="50%" align="right" valign="top"><?php echo tep_image_submit('button_login.gif'IMAGE_BUTTON_LOGIN); ?></td> 
</tr> 
</table></form></td> 
</tr> 
</table></td> 
<!-- body_text_eof //--> 
<td width="<?php echo BOX_WIDTH?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH?>" cellspacing="0" cellpadding="2">


Now let's take a look at it...
__________________
The deal is not to know everything, but to know the email of the one who does.

Reply With Quote
  #3  
Old October 15th, 2003, 11:50 PM
manoloweb manoloweb is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Monterrey MX
Posts: 49 manoloweb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
I think you can do what you want, but it will be very hard if you (as you said) know nothing of PHP or MySQL.

As far as I can see, the function that checks the user-password is not here, but in the included file 'includes/application_top.php'

The function that apparently you need to modify is called tep_validate_password()

I don't know the code, but maybe making a foreach loop inside that function could be the answer.


Reply With Quote
  #4  
Old October 16th, 2003, 12:20 AM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 7
Frankie, Please from now on make sure to post just bits and pieces of code you are having problems with. When you post PHP or Code make sure to use the appropriate Forum tags so that the text is reader friendly.

Thanks.
__________________
-- Jason

Reply With Quote
  #5  
Old October 21st, 2003, 03:13 PM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 653 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
Re: need help create a loop here

Quote:
Originally posted by frankie
this program that i want to modify now searchases the table customers for a matching email and if the match is made it checks for the password if the password fails it gives a login fail and if matches then it logs the customer in, i need it modified to do these
check for the matching email after the match is made compare the password if the password matches then login the customer if the match fails it should continue searching the db for another email match and continue this process untill either a match is made or no more customers.
i am very very new and rally know nothing about php and mysql and would really appreciate any help you can provide


Ok.. think about it this way...

If you have a database of customers, you shouldnt have the capability of having multiple customers with the same email address.. IE: Joe smith , whos email address is jsmith@aol.com, John smith should not be able to use that same email address.. right? so that kind of check should be put into place first off..

search by the primary key.. what kind of database are you using?

I'll do my example with sql...

assuming your database is setup correctly
PHP Code:
 $email $_POST["email"];
$emPass md5($_POST["emPass"]);
$query "SELECT * From 'DBUsers' where Email='$email'";
$querResults mysql_query($query);
if (
$querResults 1){
    
$query "Select * from 'DBUsers' where Email='$email' and EmailPass='$emPass'";
    
$querResults mysql_query($query);
    if (
$querResults) {
        echo 
"You found the user and the password was correct!";
    }
    else {
        echo 
"You found the user but the password was wrong";
    }
else { 
    echo 
"The user was not found.";


again, thats going on the assumption that your database is setup the same way as mine... but that right there would give you the definite if they exist, and then if the password was correct, of course the code is not perfect, so dont use it, but you can base your own logic off of it... i dont have the time to sit down and write a code, but that's a good foundation... you really DONT need a huge routine to see if they exist... you just need to plan it right and have a set of rules for your criteria

HTH

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > need help create a loop here


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |