@@ -8,6 +8,7 @@ function checkInvalidCharacters($text) {
8
8
return (bool ) preg_match ("/[^\w-.]/ " , $ text );
9
9
}
10
10
11
+ //------------------------------------------------------------------
11
12
//Function to encrypt the users Password
12
13
function encrypt_pswd ($ input , $ rounds = 9 ){
13
14
@@ -23,24 +24,28 @@ function encrypt_pswd($input , $rounds = 9 ){
23
24
return crypt ($ input , sprintf ('$2a$%02d$ ' , $ rounds ) . $ salt );
24
25
}
25
26
27
+ //-------------------------------------------------------------------------------------------
28
+ //Function to log the user out
26
29
function log_out () {
27
30
28
31
session_destroy ();
29
32
echo "<script>location='login2.php'</script> " ;
30
33
}
31
34
35
+ //-------------------------------------------------------------------------------------------
36
+ //Function to change the user's password
32
37
function change_password ($ user ) {
33
38
34
39
require ('connect.php ' );
35
40
36
41
echo "<center><br/><hr/><br/><br/>
37
42
<form action = account.php?action=cp method = 'POST'>
38
43
Current Password :
39
- <input type = 'password' name = 'curr_pass'><br/>
44
+ <input type = 'password' name = 'curr_pass'><br/><br/>
40
45
New Password :
41
- <input type = 'password' name = 'new_pass'><br/>
46
+ <input type = 'password' name = 'new_pass'><br/><br/>
42
47
Retype New Password :
43
- <input type = 'password' name = 'new_pass2'><br/>
48
+ <input type = 'password' name = 'new_pass2'><br/><br/>
44
49
<input type = 'submit' name = 'change_pass' value = 'Change My password'><br/>
45
50
</form>
46
51
</center> " ;
@@ -77,16 +82,14 @@ function change_password($user) {
77
82
78
83
//$query = mysqli_query($link , "UPDATE users SET password = '".$new_pass."' WHERE username = '".$user."'");
79
84
80
- $ sql = "UPDATE users SET password = ?
81
- WHERE username = $ user;
82
- " ;
85
+ $ sql = "UPDATE users SET password = ? WHERE username = $ user; " ;
83
86
84
- $ stmt = $ link ->prepare ($ sql );
85
- $ stmt ->bind_param ('s ' , $ password );
87
+ $ stmt2 = $ link ->prepare ($ sql );
88
+ $ stmt2 ->bind_param ('s ' , $ password );
86
89
87
90
//$res = mysqli_query($link , $sql);
88
91
89
- if ($ stmt ->execute ())
92
+ if ($ stmt2 ->execute ())
90
93
{
91
94
echo "<h3 style='text-align:center; color:green;'>Your Password has been Changed </h3> " ;
92
95
}
@@ -118,5 +121,66 @@ function change_password($user) {
118
121
}
119
122
120
123
}
124
+
125
+ //-------------------------------------------------------------------------------------------
126
+ //Function to change the user's dp
127
+ function change_image ($ user ) {
128
+
129
+ require ('connect.php ' );
130
+
131
+ echo "<center><br/><hr/><br/><br/>
132
+ <form action = account.php?action=ci method = 'POST' enctype='multipart/form-data'>
133
+ Allowed File Extensions : <b><br/><br/><ul style = 'display:table; margin:0 auto;'><li>PNG</li><li>JPG</li><li>JPEG</li></ul></b><br/>
134
+ <input type = 'file' name = 'image'><br/><br/>
135
+ <input type = 'submit' name = 'change_img' value = 'Change My Profile Picture'><br/>
136
+ </form>
137
+ </center> " ;
138
+
139
+ if (isset ($ _POST ['change_img ' ]))
140
+ {
141
+ $ errors = array ();
142
+ $ allowed_ext = array ('png ' , 'jpg ' , 'jpeg ' );
143
+
144
+ $ filename = $ _FILES ['image ' ]['name ' ];
145
+ $ file_ext = strtolower (pathinfo ($ filename , PATHINFO_EXTENSION ));
146
+ $ file_s = $ _FILES ['image ' ]['size ' ];
147
+ $ file_tmp = $ _FILES ['image ' ]['tmp_name ' ];
148
+
149
+ if (in_array ($ file_ext , $ allowed_ext ) === false )
150
+ $ errors [] = '<div style = "color:red">This type of file is not supported</div> ' ;
151
+
152
+ if ($ file_s > 2097152 )
153
+ $ errors [] = '<div style = "color:red">File size must be under <b>2 MB</b></div> ' ;
154
+
155
+ if (empty ($ errors ))
156
+ {
157
+ move_uploaded_file ($ file_tmp , 'images/ ' . $ filename );
158
+ $ image_up = 'images/ ' . $ filename ;
159
+
160
+ if ($ query_i = mysqli_query ($ link , "UPDATE users SET profile_pic = ' " .$ image_up ."' WHERE username = ' " .$ user ."' " ))
161
+ echo "<h3 style='text-align:center; color:green;'>Your Profile Picture has been Changed </h3> " ;
162
+ else
163
+ {
164
+ echo "<h3 style='text-align:center; color:red;'>Couldnot change your password</h3> " ;
165
+ echo "Error is => " . mysqli_error ($ link );
166
+
167
+ }
168
+ }
169
+
170
+ else
171
+ {
172
+ foreach ($ errors as $ error ) {
173
+ echo $ error , '<br/> ' ;
174
+ }
175
+ }
176
+
177
+ }
178
+
179
+
180
+ }
181
+
182
+ //---------------------------------------------------------------------------------------------------
183
+
184
+
121
185
122
186
?>
0 commit comments