Login   Register  
PHP Classes
elePHPant
Icontem

File: passwdAdmin.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Daniel Kushner  >  PasswdAuth  >  passwdAdmin.php  >  Download  
File: passwdAdmin.php
Role: ???
Content type: text/plain
Description: Example usage of the PasswdAuth API. Enable the addition, deletion and change password of users in the htaccess file
Class: PasswdAuth
Author: By
Last change:
Date: 2002-01-14 04:33
Size: 3,032 bytes
 

Contents

Class file image Download
<?php
include('class.PasswdAuth.inc');
$pass = new PasswdAuth();

echo "<h1>.htpasswd Admin</h1>";

function editForm($user) {
    global $PHP_SELF;
    $form = <<< END
<form action="$PHP_SELF" method="get">
    Please enter a new password for $user:<br>
    <input type="Text" size="20" name="password"><br>
    <input type="Hidden" name="user" value="$user">
    <input type="Hidden" name="action" value="doChange">
    <input type="Submit">
</form>
END;
echo $form;
}  

function addForm() {
    global $PHP_SELF;
    $form = <<< END
<form action="$PHP_SELF" method="get">
    Please enter a new user and password:<br>
    User: <input type="Text" size="20" name="user"><br>
    Password: <input type="Text" size="20" name="password"><br>
    <input type="Hidden" name="action" value="doAdd">
    <input type="Submit">
</form>
END;
echo $form;
}    

function users() {
    global $pass, $PHP_SELF;
    echo "<a href=\"$PHP_SELF?action=add\">Add a new user</a><p>";
    echo "<a href=\"secure_page.php\" target=\"_blank\">Check secure page</a> (Use one of the users below to enter this page)<p>";
    echo "<a href=\"secure_page_admin.php\" target=\"_blank\">Check secure <strong>admin</strong> page</a> (Only the user 'admin' can enter this page)<p>";
    $users = &$pass->getUsers();
    foreach($users as $user) {
        echo "$user ";
        echo "<a href=\"$PHP_SELF?action=change&user=$user\">[Change password]</a> ";
        echo "<a href=\"$PHP_SELF?action=delete&user=$user\">[Delete]</a><br>";
        
    }
}


if(isset($HTTP_GET_VARS['action'])) {
    switch($HTTP_GET_VARS['action']) {
    
        case 'change':
            editForm($HTTP_GET_VARS['user']);
            break;
            
        case 'doChange':
            if($pass->changePassword($HTTP_GET_VARS['user'], $HTTP_GET_VARS['password'])) {
                echo "Password was changed<br>";
            } else {
                echo "Password was not changed<br>";
            }
            echo "<a href=\"$PHP_SELF\">Back</a>";
            break;
            
        case 'add':
            addForm();
            break;
            
        case 'doAdd':
            if($pass->addUser($HTTP_GET_VARS['user'], $HTTP_GET_VARS['password'])) {
                echo "The user $HTTP_GET_VARS[user] was added<br>";
            } else {
                echo "The user $HTTP_GET_VARS[user] was not added<br>";
            }
            echo "<a href=\"$PHP_SELF\">Back</a>";
            break;
            
        case 'delete':
            if($pass->deleteUser($HTTP_GET_VARS['user'])) {
                echo "The user $HTTP_GET_VARS[user] was deleted<br>";
            } else {
                echo "The user $HTTP_GET_VARS[user] was not deleted<br>";
            }
            echo "<a href=\"$PHP_SELF\">Back</a>";
            break;
            
        default:
            users();
            break;
            
    }
} else {
    users();
}

?>