head	1.2;
access;
symbols;
locks; strict;
comment	@# @;


1.2
date	2001.01.30.21.36.14;	author edk;	state dead;
branches;
next	1.1;

1.1
date	2001.01.30.21.31.57;	author edk;	state Exp;
branches;
next	;


desc
@@


1.2
log
@switch from using tokens to using the environment
@
text
@#!/usr/bin/perl

use Getopt::Long;

main();

sub main {
    my $options = getOptions();
    my $list = getList();
    $main::dbh = getDatabaseConnection();
    checkList($main::dbh, $list);
    checkAll($main::dbh);
}


sub getList {
    return {
        'q' => 'a',
        'root' => 'changeme',
    };
}

# we check these through checkAll (since their passwords are the same as
# their logins):
#       'testcontdev', 'testdev', 'testdomadmin', 'testhostadmin', 
#       'testobserver', 'testowner', 'testreguser'
        

sub checkList {
    my ($dbh, $list) = @@_;

    my $sql = "SELECT loginID from User where ";
    my $first = 1;
    while (my ($id,$pass) = each %$list) {
        $sql .= " or " unless $first;
        $first = 0;

        $sql .= " (loginID = '$id' and password = password('$pass')) ";
    }

    my $select  = $dbh->prepare($sql);
    my $ret  = $select->execute();
    warn "error checking list" if not $ret;

    while (my $userRecord = $select->fetchrow_hashref) {
        my $loginID = $userRecord->{'loginID'};
        print "login $loginID has the default password!\n";
    }
}

sub checkAll {
    my ($dbh) = @@_;
    my $sql = "SELECT loginID from User where password = password(loginID)";
    my $select = $dbh->prepare($sql);
    my $ret = $select->execute();
    warn "error checking all" if not $ret;
    while (my $userRecord = $select->fetchrow_hashref) {
        my $loginID = $userRecord->{'loginID'};
        print "login $loginID has the same password as username!\n";
    }
}


use DBI;  
END { $main::dbh->disconnect if $main::dbh }

sub getDatabaseConnection {
    my $db_base = 'mysql';
    my $db_name = '__DATABASE_NAME__';
    my $db_host = '__DATABASE_HOST__';
    my $db_port = '__DATABASE_PORT__';
    my $db_user = '__DATABASE_USER__';
    my $db_pass = '__DATABASE_PASSWORD__';
    my $connectstring = "dbi:$db_base:$db_name:host=$db_host:port=$db_port";
    my $dbh = DBI->connect($connectstring, $db_user, $db_pass)
        or die "Can't connect to the table '$connectstring'.\n";
    return $dbh;
}

sub getOptions {
    my %options;
    if (!GetOptions(\%options, "help") 
            or $options{help}) {
        showUsage();
    }
    return \%options;
}

sub showUsage {
    my ($message) = @@_;
    print <<EOM;
Usage: check_passwords
EOM
    exit;
}

@


1.1
log
@a simple script to verify that the passwords are no longer the default
values.  this also marks any accounts which have been added w/ usernames
the same as their passwords
@
text
@@

