diff -urNp modules.old/regcode/regcode.info modules/regcode/regcode.info
--- modules.old/regcode/regcode.info	1969-12-31 19:00:00.000000000 -0500
+++ modules/regcode/regcode.info	2007-03-28 09:36:52.250000000 -0400
@@ -0,0 +1,4 @@
+; $Id: regcode.info,v 1.1 2007/01/03 01:29:15 drewish Exp $
+name = Regcode
+description = Implement a registration code on the User Registration page.
+package = Regcode
\ No newline at end of file
diff -urNp modules.old/regcode/regcode.module modules/regcode/regcode.module
--- modules.old/regcode/regcode.module	2007-03-28 10:27:35.000000000 -0400
+++ modules/regcode/regcode.module	2007-03-28 10:29:15.296875000 -0400
@@ -1,65 +1,160 @@
 <?php
-// $Id$
+// $Id: regcode.module,v 1.1 2007/02/22 20:10:18 colan Exp $
 
 /**
 * @file
 * regcode.module
 */
 
+// Initial written by nevets (http://drupal.org/user/12856).
+// See http://drupal.org/node/85861 for details.
+// Edited and hacked on by colan (http://drupal.org/user/58704).
+// Updated for 5.x by kaushik_sarkar (http://drupal.org/user/95377).
+// Tweaked slightly by vermi (http://drupal.org/user/114420).
+
 /**
-* Implementation of hook_help().
+* Display help and module information.
+*
+* @param section
+* which section of the site we're displaying help
+* @return
+* help text for section
 */
 function regcode_help($section) {
-  switch ($section) {
-    case 'admin/help#regcode':
-      return t('Allows the administrator to set a registration code that new users must enter before they can complete the registration process');
-    case 'admin/modules#description':
-      return t('If enabled user must enter a registration code to register');
-  }
+switch ($section) {
+case 'admin/help#regcode':
+return t('
+
+Allows administrators to set a registration code or codes
+that new users must enter before they can complete the registration
+process. If a new user enters a code that is not in the list of
+valid codes, he or she is denied registration.
+
+To set the codes, go to Administer->Site Configuration->Regcode and enter
+them there. To disable the registration code requirement for new
+users, simply disable the module (in administer->modules).
+
+');
+case 'admin/modules#description':
+return t('If enabled, users must enter a valid registration code to
+register');
+}
 }
 
+/**
+* Set valid permissions for this module.
+*
+* @return
+* An array of valid permissions for the module
+*/
+function regcode_perm() {
+return array('administer registration codes');
+}
 
 /**
-* Implementation of hook_settings().
+* Declare administrative settings for a module.
+*
+* @return
+* An array containing form items to place on the module settings page
 */
-function regcode_settings() {
-$form['regcode_code'] = array(
+/* Actually hook_setting does not work in Drupal 5.1 environment So, the equivalent is hook_menu($may_cache) api, I implement this api
+*/
+function regcode_menu($may_cache)
+{
+$items = array();
+
+$items[] = array('path' => 'admin/settings/regcode',
+'title' => t('Regcode'),
+'callback' => 'drupal_get_form',
+'callback arguments' => array('regcode_admin_settings'),
+'access' => user_access('administer registration codes
+'),
+'description' => t('Display registration code on the registration page.')
+
+);
+
+return $items;
+
+}//end of function regcode_menu
+
+function regcode_admin_settings()
+{
+$form = array();
+
+$form['regcode_title'] = array(
 '#type' => 'textfield',
-'#title' => t('Registration Code'),
+'#title' => t('Field Name'),
 '#required' => TRUE,
-'#default_value' => variable_get('regcode_code', ''),
-'#description' => t('If set, new user must correctly enter this code in order to register')
+'#default_value' => t('Registration Code'),
+'#description' => t('This will change the name of the Registration Code field on the New User Registration page.')
 );
 
-return $form;
-}
+$form['regcode_desc'] = array(
+'#type' => 'textarea',
+'#title' => t('Description'),
+'#required' => TRUE,
+'#default_value' => t('Please enter your registration code.'),
+'#description' => t('Change this to customize the descriptive text new users will see beneath the Registration Code box on the New User Registration page.')
+);
+
+$form['regcode_codes'] = array(
+'#type' => 'textarea',
+'#title' => t('Registration Code(s)'),
+'#required' => TRUE,
+'#default_value' => variable_get('regcode_codes', ''),
+'#description' => t('If set, new users must correctly enter one of these
+codes in order to register. Enter one code per line.')
+);
 
+return system_settings_form($form);
 
+}
 /**
-* Implementation of hook_user().
+* Act on user account actions.
+*
+* @param $op
+* The kind of action is being performed
+* @param $edit
+* The array of form values submitted by the user
+* @param $account
+* The user object on which the operation is being performed
+* @param $category
+* The active category of user information being edited
+* @return
+* This varies depending on the operation.
 */
 function regcode_user($op, &$edit, &$account, $category = NULL) {
-$regcode =  trim(variable_get('regcode_code', ''));
-if ( $regcode ) {
-switch ( $op ) {
+
+// Get the array of registration codes.
+$regcodes = variable_get('regcode_codes', '');
+
+// Only do the checking if the codes variable is set.
+if (strlen(trim($regcodes))) {
+switch ($op) {
+
 case 'register':
+// Inject the registration code field into the registration form.
 $form['regcode_code'] = array(
 '#type' => 'textfield',
-'#title' => t('Registration Code'),
+'#title' => variable_get('regcode_title', ''),
+//'#default_value' => variable_get('regcode_codes', ''),
 '#required' => TRUE,
-'#description' => t('Please enter your registration code.')
+'#description' => variable_get('regcode_desc', '')
 );
 return $form;
 
 case 'validate':
-if ( $category == 'account' ) {
-if ( $regcode != $edit['regcode_code'] ) {
+if (! $account->uid && $category == 'account') {
+// Make sure that the entered code is in the list.
+$regcodes = explode("\n", $regcodes);
+array_walk($regcodes, create_function('&$a', '$a = trim($a);'));
+if (!in_array(trim($edit['regcode_code']), $regcodes)) {
 form_set_error('regcode_code', t('Invalid registration code'));
+watchdog('regcode', t('User entered invalid registration code: ') .
+$edit['regcode_code'], WATCHDOG_WARNING);
 }
 }
 break;
-
 }
-
 }
 }
\ No newline at end of file
