#######################################################
  $Id: change_password.php

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

  Copyright (c) 2007 osCommerce

  Released under the GNU General Public License

V1.0 by Dave - AdvancedStyle.com

V2.0 multilanguage + french version added by Maverick

V2.1 german version added by gsvarel

V2.2 Control of the input added by smhh

V3.0 Bugfixes and features by kymation

V3.2 corrected full package by luckyno

v3.3 correction for incompatibility by reflex-ocasion

v4.0 now works in v2.3.3 and up

#######################################################

This simple contribution creates a page in the admin area where you can
select any customer and enter a new password.


#######################################################

UPDATE V3.3 >> V4.0

Only replace your files   >>> but >>> BACKUP!!! BACKUP!!! BACKUP!!!

#######################################################
Installation:
#######################################################

*******************************
Step 1: BACKUP
*******************************
BACKUP!!! BACKUP!!! BACKUP!!!


*******************************
Step 2: COPY FILES
*******************************
Copy the following files in this package into your admin folder:

catalog/admin/change_password.php
catalog/admin/includes/languages/english/change_password.php
catalog/admin/includes/languages/english/images/buttons/button_change_password.gif
catalog/admin/includes/functions/password_funcs.php


*******************************
Step 3: ADD
*******************************
catalog/admin/includes/filenames.php

just before the last ?>

ADD
// Change Password
define('FILENAME_CHANGE_PASSWORD', 'change_password.php');


*******************************
Step 4: LANGUAGE TRANSLATION
*******************************
catalog/admin/includes/languages/english.php

Find
define('BOX_CUSTOMERS_ORDERS', 'Orders');

ADD AFTER
// Change Password
define('BOX_CUSTOMERS_CHANGE_PASSWORD', 'Change Password');

Find
// images

ADD AFTER
define('IMAGE_CHANGE_PASSWORD', 'Change Password');


*******************************
Step 5: ADD
*******************************
catalog/admin/includes/boxes/customers.php

FIND
    array(
        'code' => FILENAME_CUSTOMERS,
        'title' => BOX_CUSTOMERS_CUSTOMERS,
        'link' => tep_href_link(FILENAME_CUSTOMERS)
      ),


ADD AFTER
    array(
        'code' => FILENAME_CHANGE_PASSWORD,
        'title' => BOX_CUSTOMERS_CHANGE_PASSWORD,
        'link' => tep_href_link(FILENAME_CHANGE_PASSWORD)
      ),

*******************************
Step 6: REPLACE
*******************************
catalog/admin/customers.php

FIND
        $contents[] = array('align' => 'center', 'text' => tep_draw_button(IMAGE_EDIT, 'document', tep_href_link(FILENAME_CUSTOMERS, tep_get_all_get_params(array('cID', 'action')) . 'cID=' . $cInfo->customers_id . '&action=edit')) . tep_draw_button(IMAGE_DELETE, 'trash', tep_href_link(FILENAME_CUSTOMERS, tep_get_all_get_params(array('cID', 'action')) . 'cID=' . $cInfo->customers_id . '&action=confirm')) . tep_draw_button(IMAGE_ORDERS, 'cart', tep_href_link(FILENAME_ORDERS, 'cID=' . $cInfo->customers_id)) . tep_draw_button(IMAGE_EMAIL, 'mail-closed', tep_href_link(FILENAME_MAIL, 'customer=' . $cInfo->customers_email_address)));

REPLACE WITH
// Change Password
        $contents[] = array('align' => 'center', 'text' => tep_draw_button(IMAGE_EDIT, 'document', tep_href_link(FILENAME_CUSTOMERS, tep_get_all_get_params(array('cID', 'action')) . 'cID=' . $cInfo->customers_id . '&action=edit')) . tep_draw_button(IMAGE_DELETE, 'trash', tep_href_link(FILENAME_CUSTOMERS, tep_get_all_get_params(array('cID', 'action')) . 'cID=' . $cInfo->customers_id . '&action=confirm')) . tep_draw_button(IMAGE_ORDERS, 'cart', tep_href_link(FILENAME_ORDERS, 'cID=' . $cInfo->customers_id)) . tep_draw_button(IMAGE_EMAIL, 'mail-closed', tep_href_link(FILENAME_MAIL, 'customer=' . $cInfo->customers_email_address)) . tep_draw_button(IMAGE_CHANGE_PASSWORD, 'key', tep_href_link(FILENAME_CHANGE_PASSWORD, 'customer=' . $cInfo->customers_id)));

*******************************
Step 7: ADD
*******************************
catalog/admin/includes/functions/general.php

ADD just before the final ?>
// Change password -- copied from catalog/includes/functions/general.php
   function tep_create_random_value($length, $type = 'mixed') {
    if ( ($type != 'mixed') && ($type != 'chars') && ($type != 'digits')) $type = 'mixed';

    $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $digits = '0123456789';

    $base = '';

    if ( ($type == 'mixed') || ($type == 'chars') ) {
      $base .= $chars;
    }

    if ( ($type == 'mixed') || ($type == 'digits') ) {
      $base .= $digits;
    }

    $value = '';

    if (!class_exists('PasswordHash')) {
      include(DIR_WS_CLASSES . 'passwordhash.php');
    }

    $hasher = new PasswordHash(10, true);

    do {
      $random = base64_encode($hasher->get_random_bytes($length));

      for ($i = 0, $n = strlen($random); $i < $n; $i++) {
        $char = substr($random, $i, 1);

        if ( strpos($base, $char) !== false ) {
          $value .= $char;
        }
      }
    } while ( strlen($value) < $length );

    if ( strlen($value) > $length ) {
      $value = substr($value, 0, $length);
    }

    return $value;
  }

*******************************
Step 8: OPTIONAL
*******************************
If you are using Admin Access Level, don't forget to declare the file change_password.php in the Customers Box....


*******************************
Step 9: GO
*******************************
Go to Admin -> Customers -> Change Passwords
or Admin -> Customers -> Customers


*******************************
Step 10: SUPPORT
*******************************
For support see the forum thread:
http://forums.oscommerce.com/index.php?showtopic=285118

