-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblog_edit_user.php
151 lines (131 loc) · 3.9 KB
/
blog_edit_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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
include('core/init.inc.php');
include('login/login.func.php');
sec_session_start($mysqli);
if(login_check($mysqli) == true) {
} else {
$_SESSION['URI'] = curPageURL();
header("Location: login/login.php");
die('Você não está autorizado a acessar esta página. Por favor, efetue login. <br/>');
}
$message = "";
if(isset($_POST['newpwd'], $_POST['oldpwd'])){
if (passwd_verify($_POST['p'], $_SESSION['email'], $mysqli)){
$password = $_POST['po'];
// Cria um salt randômico
$random_salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true));
// Cria uma senha pós hash (Cuidado para não re-escrever)
$password = hash('sha512', $password.$random_salt);
// Adicione sua inserção ao script de base de dados aqui
// Certifique-se de utilizar declarações preparadas
$query = "UPDATE `members` SET `password` = '".$password."', `salt` = '".$random_salt."' WHERE `members`.`id` = '".$_SESSION['user_id']."'";
if ($insert_stmt = $mysqli->prepare($query)) {
$insert_stmt->execute();
$message = "<h3 style=\"color: green;\">Palavra passe alterada.</h3>";
}
}
else{
$message = "<h3 style=\"color: red;\">Palavra passe introduzida não corresponde ao utilizador atual.</h3>";
}
}
if (isset($_POST['about'], $_POST['userid'])){
change_about($_POST['userid'], $_POST['about'], $mysqli);
$message = "<h3 style=\"color: green;\">Sobre ".$_SESSION['username']." alterado.</h3>";
}
echo '<!DOCTYPE HTML>
<html>';
include('resources/head.php');
echo
'
<body>
<div id="main">
';
include('resources/github_ribbons.php');
$current = 'user';
include('resources/header.php');
echo
'
<div id="site_content">
';
include('resources/sidebar.php');
echo
'
<div id="content">
<article>
<header>
<h1>Alterar dados de conta</h1>
'.$message.'
';
echo
'<form action="" method="post" name="change_pass_form" >
<fieldset>
<legend>Palavra passe de '.$_SESSION['username'].':</legend>
<p style="text-align: left;">
<label for="oldpwd">Palavra passe atual</label>
<input type="password" name="oldpwd" id="oldpwd" required />
</p>
<p style="text-align: left;">
<label for="newpwd">Nova palavra passe</label>
<input type="password" name="newpwd" id="newpwd" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z])\w{6,}"
onchange=" this.setCustomValidity(this.validity.patternMismatch ?
\'Password deve conter pelo menos 6 caracteres, incluindo MAIÚSCULAS/minúsculas e numero(s)\' : \'\');
if(this.checkValidity()) form.reppwd.pattern = this.value;" />
</p>
<p style="text-align: left;">
<label for="reppwd">Repetir a nova palavra passe</label>
<input type="password" name="reppwd" id="reppwd" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z])\w{6,}"
onchange=" this.setCustomValidity(this.validity.patternMismatch ?
\'Introduza a mesma password que colocou acima\' : \'\');" />
</p>
<p>
<input type="submit" value="Enviar" onclick="sendForm(this.form, this.form.oldpwd, this.form.newpwd);" />
</p>
</fieldset>
</form>';
$user = get_user($_SESSION['user_id'], $mysqli);
echo
'<br />
<form action="" method="post" name="change_about_form" >
<fieldset>
<legend>Sobre '.$_SESSION['username'].':</legend>
<p>
<textarea name="about" id="about" >'.$user['about'].'</textarea>
<input type="hidden" name="userid" id="userid" value="'.$_SESSION['user_id'].'" />
</p>
<p>
<input type="submit" value="Enviar" />
</p>
</fieldset>
</form>
</header>
</article>
';
include('tinyMCE/init.php');
echo
'
<script type="text/javascript" src="login/sha512.js"></script>
<script type="text/javascript" src="login/forms.js"></script>
<script>
function sendForm(form, field1, field2) {
aux1 = field1.value;
aux2 = field2.value;
formhash(form, field1, \'p\');
formhash(form, field2, \'po\');
field1.value = aux1;
field2.value = aux2;
form.submit();
return true;
}
</script>
';
echo
'</div>
</div>
';
include('resources/footer.php');
echo
'
</div>
</body>
</html>';
?>