Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Diff of /createPasswords/trunk/createPasswords.mysqli.php [000000] .. [r188] Maximize Restore

  Switch to side-by-side view

--- a
+++ b/createPasswords/trunk/createPasswords.mysqli.php
@@ -0,0 +1,74 @@
+<?php
+## Copyright 2007 Kyle Hall
+
+## This file is part of koha-tools.
+
+## koha-tools is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+
+## koha-tools is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+
+## You should have received a copy of the GNU General Public License
+## along with koha-tools; if not, write to the Free Software
+## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+/**
+  * Creates a default login and password for all borrowers who do not have one yet.
+  * The login and password are set to the borrowers cardnumber, but this script
+  * could be modified easily to change the login and password to other things.
+  * @package koha-tools
+  * @subpackage createPasswords
+  * @author Kyle Hall
+  * @copyright 2007
+  */
+
+ini_set("memory_limit", "256M");
+
+require_once("classes/MySQLConnectionFactory.class.php");
+
+$mysqli = MySQLConnectionFactory::createi();
+
+$query = 'SELECT cardnumber FROM borrowers WHERE password IS NULL';
+
+$patronData = array();
+if ( $result = $mysqli->query( $query ) ) {
+
+  /* fetch associative array */
+  while ( $row = $result->fetch_assoc() ) {
+    $cardnumber = $row['cardnumber'];
+    $userid = $cardnumber;
+    $password = md5_base64( $cardnumber );
+    
+    $query = $mysqli->prepare("UPDATE borrowers SET password = ?, userid = ? WHERE cardnumber = ?");
+    $query->bind_param( 'sss', $password, $userid, $cardnumber );
+    $query->execute();
+    if ( $mysqli->error ) {
+      try {    
+        throw new Exception("MySQL error $mysqli->error <br> Query:<br> $query", $msqli->errno);    
+      } catch( Exception $e ) {
+        echo "Error No: ".$e->getCode(). " - ". $e->getMessage() . "<br >";
+        echo nl2br($e->getTraceAsString());
+      }
+    } else {
+     echo "Created password hash $password and userid $userid for cardnumber $cardnumber\n";
+     echo $mysqli->info . "\n";
+
+    }
+  }
+
+  /* free result set */
+  $result->close();
+} else { printf("Connect failed: %s\n", $mysqli->error ); }
+
+function md5_base64 ( $data ) {
+  return rtrim( base64_encode( pack( "H*", md5( $data ) ) ), "=" );
+#  return preg_replace( '/=+$/', '', base64_encode( pack( 'H*', md5( $data ) ) ) );
+} 
+?>
+
+