about summary refs log tree commit diff stats
path: root/central/trunk/changepassword.php
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2008-08-15 18:39:18 +0000
committerKelly Rauchenberger <fefferburbia@gmail.com>2008-08-15 18:39:18 +0000
commit9aec4d669f8d9efb74372e3755131e042c62761f (patch)
tree8fd2491e1efb923392e3b8a39ce045d83f94bd9a /central/trunk/changepassword.php
parent4c9677691d59bd6d743bd544b6be38084e095a22 (diff)
downloadinstadisc-9aec4d669f8d9efb74372e3755131e042c62761f.tar.gz
instadisc-9aec4d669f8d9efb74372e3755131e042c62761f.tar.bz2
instadisc-9aec4d669f8d9efb74372e3755131e042c62761f.zip
Central: Add change password
Refs #25 and closes #35
Diffstat (limited to 'central/trunk/changepassword.php')
-rw-r--r--central/trunk/changepassword.php118
1 files changed, 118 insertions, 0 deletions
diff --git a/central/trunk/changepassword.php b/central/trunk/changepassword.php new file mode 100644 index 0000000..bdbcf6e --- /dev/null +++ b/central/trunk/changepassword.php
@@ -0,0 +1,118 @@
1<?php
2
3/* InstaDisc Server - A Four Island Project */
4
5include('includes/instadisc.php');
6include('includes/template.php');
7
8if (!isset($_GET['submit']))
9{
10 showForm('','','',array());
11} else {
12 $numOfErrors = 0;
13 $errors = array();
14
15 if ($_POST['old'] == '')
16 {
17 addError($numOfErrors, $errors, 'old', 'Old Password is a required field');
18 } else {
19 $getuser = "SELECT * FROM users WHERE username = \"" . mysql_real_escape_string($_SESSION['username']) . "\" AND password = \"" . mysql_real_escape_string(md5($_POST['old'])) . "\"";
20 $getuser2 = mysql_query($getuser);
21 $getuser3 = mysql_fetch_array($getuser2);
22
23 if ($getuser3['password'] != md5($_POST['password']))
24 {
25 addError($numOfErrors, $errors, 'old', 'Old password is not correct');
26 }
27 }
28
29 if ($_POST['new'] == '')
30 {
31 addError($numOfErrors, $errors, 'new', 'New Password is a required field');
32 }
33
34 if ($_POST['confirm'] == '')
35 {
36 addError($numOfErrors, $errors, 'confirm', 'Confirm New Password is a required field');
37 }
38
39 if ($_POST['new'] != $_POST['confirm'])
40 {
41 addError($numOfErrors, $errors, 'confirm', 'Passwords do not match');
42 }
43
44 if ($numOfErrors > 0)
45 {
46 showForm($_POST['old'], $_POST['new'], $_POST['confirm'], $errors);
47 } else {
48 instaDisc_changePassword($_SESSION['username'], $_POST['new']);
49
50 $template = new FITemplate('changedpassword');
51 $template->add('SITENAME', instaDisc_getConfig('siteName'));
52 $template->display();
53 }
54}
55
56function showForm($old, $new, $confirm, $errors)
57{
58 $template = new FITemplate('changepassword');
59 $template->add('SITENAME', instaDisc_getConfig('siteName'));
60
61 if (isset($errors[1]))
62 {
63 $template->adds('ERROR', array('ex'=>'1'));
64
65 foreach ($errors as $name => $value)
66 {
67 $template->adds('ERRORS', array( 'NAME' => $name,
68 'MSG' => $value['msg']));
69 }
70 }
71
72 $template->add('OLD_ERR', ifErrors($errors, 'old'));
73 $template->add('NEW_ERR', ifErrors($errors, 'new'));
74 $template->add('CONFIRM_ERR', ifErrors($errors, 'confirm'));
75
76 doErrors($template, $errors, 'old');
77 doErrors($template, $errors, 'new');
78 doErrors($template, $errors, 'confirm');
79
80 $template->add('OLD', $old);
81 $template->add('NEW', $new);
82 $template->add('CONFIRM', $confirm);
83
84 $template->display();
85}
86
87function ifErrors($errors, $id)
88{
89 foreach ($errors as $name => $value)
90 {
91 if ($value['field'] == $id)
92 {
93 return ' error';
94 }
95 }
96
97 return '';
98}
99
100function doErrors($template, $errors, $id)
101{
102 foreach ($errors as $name => $value)
103 {
104 if ($value['field'] == $id)
105 {
106 $template->adds(strtoupper($id) . '_ERRS', array( 'NAME' => $name,
107 'VALUE' => $value['msg']));
108 }
109 }
110}
111
112function addError(&$numOfErrors, &$errors, $field, $msg)
113{
114 $numOfErrors++;
115 $errors[$numOfErrors] = array('field' => $field, 'msg' => $msg);
116}
117
118?>