forked from edruid/Nitroxy-retail-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.php
59 lines (53 loc) · 1.39 KB
/
user.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
require 'includes.php';
define('HTML_ACCESS', false);
ob_implicit_flush();
function getstring($str){
echo $str;
ob_flush();
return substr(fgets(STDIN),0,-1);
}
function getpass($str){
echo $str;
ob_flush();
if ( posix_isatty(0) ) system('stty -echo');
$passwd = substr(fgets(STDIN),0,-1);
if ( posix_isatty(0) ) system('stty echo');
echo "\n";
return $passwd;
}
if ( count($argv) >= 2 ){
$user = User::from_username($argv[1]);
$salt = '$5$rounds=5000$'.$argv[1];
if ( !$user ){
echo "Adding new user {$argv[1]}\n";
$user = new User;
$user->username = $argv[1];
$user->first_name = getstring("First name: ");
$user->surname = getstring("Surname: ");
$passwd1 = getpass("Enter new password: ");
$passwd2 = getpass("Retype new password: ");
if ( $passwd1 != $passwd2 ){
echo "Passwords does not match, user not added\n";
exit(1);
}
$user->password = crypt($passwd1, $salt);
$user->commit();
} else {
echo "Changing password for {$user->username}.\n";
$passwd1 = getpass("Enter new password: ");
$passwd2 = getpass("Retype new password: ");
if ( $passwd1 != $passwd2 ){
echo "Passwords does not match, password remain unchanged\n";
exit(1);
}
$user->password = crypt($passwd1, $salt);
$user->commit();
}
} else {
echo "Usage: user.php [username]\n\n";
echo "Available users:\n";
foreach ( User::selection() as $user ){
echo ' * ' . $user . "\n";
}
}