Skip to content

Commit

Permalink
Finished work on account registration
Browse files Browse the repository at this point in the history
  • Loading branch information
SSUPII committed Mar 2, 2020
1 parent d5bc5b0 commit ff406b0
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 2 deletions.
23 changes: 21 additions & 2 deletions acc/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
$strings[] = "en";
$strings[] = "Login";
$strings[] = "Register";
$strings[] = "This username is already taken";
$strings[] = "Registration completed";
break;
}
case "it":{
$strings[] = "it";
$strings[] = "Accesso";
$strings[] = "Registra";
$strings[] = "Questo username è stato già usato";
$strings[] = "Registrazione completata";
break;
}
default:{
Expand All @@ -37,7 +41,7 @@
<title>Web Musei</title>
</head>
<body>
<a href="../index.htm"><img style="float: left;" src="../res/img/back.png" /></a><img style="float: left;" src="../res/img/lang.png" /><a href="../home.php?lang=it">Italiano</a> <a href="../home.php?lang=en">English</a>
<a href="../index.htm"><img style="float: left;" src="../res/img/back.png" /></a><img style="float: left;" src="../res/img/lang.png" /><a href="./login.php?lang=it">Italiano</a> <a href="./login.php?lang=en">English</a>
<div class=headerCountainer>
<a href="../home.php?lang=<?php echo $strings[0]; ?>"><img class=icon src="../res/icon.png" alt="Web Musei" title="Home"></a>
</div>
Expand All @@ -47,8 +51,22 @@
<div class=list style="border: none;">
<div style="text-align: center">
<script type="text/javascript">
var submited;
var submited = "undefined";
</script>
<p style="color: #FF0000"><?php
if(isset($_GET["err"])){
switch($_GET["err"]){
case "-1":{
echo $strings[4];
break;
}
case "1":{
echo $strings[3];
break;
}
}
}
?></p>
<form name=log action="" method=POST onsubmit="checkps()">
Username <input type=text name=user required><br>
Password <input type=password name=pass required><br>
Expand Down Expand Up @@ -85,6 +103,7 @@ function checkps(){
}else{
document.log.action = "./sessionstart.php?lang="+lang;
}
submited = "undefined";
}
</script>
</form>
Expand Down
67 changes: 67 additions & 0 deletions acc/registration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
header('Content-type: text/html; charset=iso-8859-1');
if(isset($_GET["lang"])){
$strings = array();
switch($_GET["lang"]){
case "en":{
$strings[] = "en";
break;
}
case "it":{
$strings[] = "it";
break;
}
default:{
header('Location: http://127.0.0.1/webmuseoscuola/index.htm');
exit();
}
}
}
else {
header('Location: http://127.0.0.1/webmuseoscuola/index.htm');
exit();
}
?>
<!DOCTYPE html>
<html lang=en>
<head>
<link rel="icon" href="./favicon.ico" />
<meta charset=iso-8859-1>
<title>Web Musei</title>
</head>
<body>
Creating...
<?php
if(isset($_POST["user"]) && isset($_POST["pass"])){
$connection = mysqli_connect("127.0.0.1","root","","musei");
if($connection != FALSE){
$sql = "SELECT username FROM users WHERE username = \"$_POST[user]\"";
$result = mysqli_query($connection,$sql);
if($result != FALSE && mysqli_num_rows($result) > 0){
header("Location: http://127.0.0.1/webmuseoscuola/acc/login.php?lang=$strings[0]&err=1");
}else{
$length = 24;
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
do{
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
}while(mysqli_num_rows(mysqli_query($connection,"SELECT id FROM users WHERE id = \"$randomString\"")) > 0);
$sql = "INSERT INTO users VALUES (\"$randomString\", \"$_POST[user]\", \"".sha1($_POST["pass"])."\", 0)";
$result = mysqli_query($connection,$sql);
if($result != FALSE){
header("Location: http://127.0.0.1/webmuseoscuola/acc/login.php?lang=$strings[0]&err=-1");
}
}
}else {
header("Location: http://127.0.0.1/webmuseoscuola/acc/login.php?lang=$strings[0]");
}
}else {
header("Location: http://127.0.0.1/webmuseoscuola/acc/login.php?lang=$strings[0]");
}

?>
</body>
</html>

0 comments on commit ff406b0

Please sign in to comment.