check user existence before registering:

This commit is contained in:
gtlsgamr 2022-08-10 16:00:22 +00:00
parent 2337aa851e
commit 6e28d81f50
4 changed files with 39 additions and 5 deletions

15
header.php Normal file
View File

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/static/css/writ.css">
<body>
<header>
<h1><a href="/">~Tildevarsh</a></h1>
<nav>
<ul>
<li><a href="funds.html">funding info</a></li>
<li><a href="register.php">register</a></li>
</ul>
</nav>
</header>

View File

@ -1,5 +1,4 @@
<hr>
<footer>2022</footer>
</main>
</body>
</html>

View File

@ -1,10 +1,11 @@
<?php
include("./includes/header.php");
if($_SERVER['REQUEST_METHOD']=="POST"){
if($_POST['name']){
$username = filter_var($_POST['name'],FILTER_UNSAFE_RAW);
$username_reg = '/^[a-z_][a-z0-9_]{0,30}$/';
if(preg_match('/^'.$username.':.*'.'/m',file_get_contents('/etc/passwd') == 1)){
if(preg_match('/'.$username.':/',file_get_contents('/etc/passwd'))){
$err = "Username already exists!";
}
else if(!preg_match($username_reg,$username)){
@ -12,6 +13,7 @@ if($_SERVER['REQUEST_METHOD']=="POST"){
}
else{
$success= true;
$success_msg= "You have been registered! Please wait for an email to arrive with confirmation";
}
}
@ -46,11 +48,20 @@ if($_SERVER['REQUEST_METHOD']=="POST"){
</div>
<br>
<div class="row">
<div class="col-12">
<div class="col-6">
<input type="submit" value="Sign up"/>
</div>
<?php
if($err){?>
<div class="col-6 error"><?php echo $err ?></div>
<?php
}?>
<?php
if($success){?>
<div class="col-6 success"><?php echo $success_msg?></div>
<?php
}?>
</div>
</div>
</form>
</main>
<?php include("./includes/footer.php")?>

View File

@ -220,3 +220,12 @@ input, textarea{
font-family:inherit;
font-size:inherit;
}
.error{
color:red;
font-size:small;
}
.success{
color:green;
font-size:small;
}