#!/usr/bin/perl
# Ralf's Chat - a Perl webchat script
# Copyright 1998-2002 Ralf Gueldemeister <ralf@ralfchat.com>
#
# This file is part of Ralf's Chat.
#
# Ralf's Chat 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.
#
# Ralf's Chat 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 Ralf's Chat; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


$query{'noheader'} = 1;

require "../config.cgi";
require "../shared.cgi";

$data_dir = "../data";

if ($use_dbi) { 
# <DBI>
    # add field for new lost password function
    $dbh->do("ALTER TABLE nicks ADD reset_password_key TEXT");
    
    # convert plaintext password to MD5 hashed password
    $sth = $dbh->prepare("SELECT name, password FROM $data{'nicks'}");
    $sth->execute;
    while ($row = $sth->fetchrow_arrayref) {
	$$row[1] = md5_base64($$row[1], $$row[0]);
	$dbh->do("UPDATE $data{'nicks'} SET password = '$$row[1]' WHERE name = '$$row[0]'");
	print "$$row[0]: password converted to MD5 hash\n";
    }

# </DBI>
} else {
# <NODBI>
    &file_open("nicks", ">");
    while (<READFILENICKS>) {
        @row = split(/;;/);   
	# convert plaintext password to MD5 hashed password
	$row[1] = md5_base64($row[1], $row[0]);
	print WRITEFILENICKS join(";;", @row);
	print "$row[0]: password converted to MD5 hash\n";
    }
    &file_close("nicks", ">");
# </NODBI>
}

print "Update to v1.3 complete.\n";

