/
settings.php
100 lines (76 loc) · 2.3 KB
/
settings.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/*
Settings page. Part of My Daily Todo -project.
Copyright (C) 2009 Aleksi Räsänen <aleksi.rasanen@runosydan.net>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
session_start();
require 'general_functions.php';
function check_post_values()
{
if( isset( $_POST['password'] )
&& isset( $_POST['password_again'] ) )
{
// Passwords did not match, do not change it.
if( $_POST['password'] != $_POST['password_again'] )
return 1;
$user_file = 'users/' . $_SESSION['todo_username'] . '.txt';
$fh = @fopen( $user_file, 'w' );
if(! $fh )
{
echo 'Failed to open user file!';
return 2;
}
fwrite( $fh, 'password=' . sha1( $_POST['password'] ) . "\n" );
fclose( $fh );
return 0;
}
return 3;
}
function create_settings_page()
{
echo '<h2>Settings</h2>';
echo '<form action="settings.php" method="post">';
echo '<table>';
echo '<tr>';
echo '<td>Password</td>';
echo '<td><input type="password" name="password"></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Password again</td>';
echo '<td><input type="password" name="password_again"></td>';
echo '</tr>';
echo '<tr>';
echo '<td colspan="2"><input type="submit" value="Change"></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
echo '<br /><br /><hr />';
echo '<a href="index.php">Back to main page</a>';
echo '<br /><br />';
echo '<a href="logout.php">Logout</a>';
echo '</div>';
}
function main()
{
create_html_start();
echo '<div id="settings">';
$ret = check_post_values();
if( $ret == 0 )
echo 'Password changed!';
else if( $ret == 1 )
echo 'Passwords did not match!';
create_settings_page();
create_html_end();
}
main();
?>