<?php

$username = $_SERVER['argv'][1];

require "../constants.php";
require "../config.php";
require "../class_appdb.php";
require "../class_user.php";

$globaldbh = AppDB::getDBH();
if ( !is_object($globaldbh) || !(get_class($globaldbh) == "PDO") ) {
   header('Location: error_db.php?establish=');
   exit();
}

$user = User::getUserByUsername($username);

$p1 = readline("Enter a new password: ");
$p2 = readline("Confirm new password: ");
if ( $p1 != $p2 ) {
   echo "Error: Passwords do not match!!\n\n";
   exit();
}
$user->setPassword($p1);
$user->save();
echo "Password changed.\n\n";
exit();
   

// vim: set ts=3:sw=3
