add things from 27-03-26
This commit is contained in:
@@ -11,6 +11,7 @@ Wichtige Informationen
|
|||||||
- Registrierung weiter gemacht
|
- Registrierung weiter gemacht
|
||||||
- Passwort checks
|
- Passwort checks
|
||||||
- Passwort hashing
|
- Passwort hashing
|
||||||
|
- Email checking
|
||||||
|
|
||||||
## 25-03-26 - PHP (Unterrichts Projekt)
|
## 25-03-26 - PHP (Unterrichts Projekt)
|
||||||
- Registrierung gemacht
|
- Registrierung gemacht
|
||||||
|
|||||||
@@ -1,22 +1,5 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
|
||||||
* Check password strength (1/2)
|
|
||||||
* @param string $password password to check
|
|
||||||
* @return bool - true or false
|
|
||||||
*/
|
|
||||||
function isStrongPassword(string $password): bool
|
|
||||||
{
|
|
||||||
// min. 8 Zeichen, 1 Kleinbuchstabe, 1 Großbuchstabe, 1 Zahl, 1 Sonderzeichen
|
|
||||||
return (bool) preg_match(
|
|
||||||
'/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^a-zA-Z0-9]).{8,}$/',
|
|
||||||
$password
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check password strength (2/2)
|
* Check password strength (2/2)
|
||||||
* @param string $password password to check
|
* @param string $password password to check
|
||||||
@@ -41,7 +24,10 @@ function checkPasswordStrength(string $password): bool {
|
|||||||
//check if spec. chars
|
//check if spec. chars
|
||||||
if(preg_match('/[^a-zA-Z0-9]/', $password)) $strength++;
|
if(preg_match('/[^a-zA-Z0-9]/', $password)) $strength++;
|
||||||
|
|
||||||
|
// valid password: #Test12345
|
||||||
return($strength >= 5);
|
return($strength >= 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isValidEmail(string $email):bool {
|
||||||
|
return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
|
||||||
}
|
}
|
||||||
@@ -27,36 +27,36 @@ if(!empty($_REQUEST)) { // Button wurde gedrückt?
|
|||||||
$email = $_REQUEST['email'];
|
$email = $_REQUEST['email'];
|
||||||
$pw = $_REQUEST['pw'];
|
$pw = $_REQUEST['pw'];
|
||||||
|
|
||||||
if(isStrongPassword($pw)){ // hier kann man die gegeben Funktion nutzen oder "checkPAsswordStrength" (aus functions.php)
|
if(checkPasswordStrength($pw) AND isValidEmail($email)){
|
||||||
$pw = password_hash($pw, PASSWORD_DEFAULT);
|
$pw = password_hash($pw, PASSWORD_DEFAULT);
|
||||||
} else {
|
|
||||||
$errors .= "Passwort zu schwach!<br>";
|
|
||||||
}
|
|
||||||
|
|
||||||
$query = "INSERT INTO user VALUES (NULL, :email, :pw)";
|
$query = "INSERT INTO user VALUES (NULL, :email, :pw)";
|
||||||
$stmt = $dbh->prepare($query);
|
$stmt = $dbh->prepare($query);
|
||||||
|
|
||||||
$stmt->bindParam(':email', $email);
|
$stmt->bindParam(':email', $email);
|
||||||
$stmt->bindParam(':pw', $pw);
|
$stmt->bindParam(':pw', $pw);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
} catch(PDOException $e){
|
$errors = "Alles malocht! :)";
|
||||||
$errMsg = $e->getMessage();
|
} catch(PDOException $e){
|
||||||
$errCode = $e->getCode();
|
$errMsg = $e->getMessage();
|
||||||
|
$errCode = $e->getCode();
|
||||||
|
|
||||||
echo $e;
|
echo $e;
|
||||||
|
|
||||||
switch($errCode) {
|
switch($errCode) {
|
||||||
case "23000": $custErrMsg = "<p>Email-Adress already exists!</p>"; break;
|
case "23000": $custErrMsg = "<p>Email-Adress already exists!</p>"; break;
|
||||||
default: $custErrMsg = "<p>Oooops, something went wrong!</p>";
|
default: $custErrMsg = "<p>Oooops, something went wrong!</p>";
|
||||||
|
}
|
||||||
|
echo $custErrMsg;
|
||||||
}
|
}
|
||||||
echo $custErrMsg;
|
} else {
|
||||||
|
$errors .= "Passwort zu schwach oder Email ist ungültig !<br>";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$errors .= "Beide Felder müssen ausgefüllt werden<br>";
|
$errors .= "Beide Felder müssen ausgefüllt werden<br>";
|
||||||
} // Ende Felder müssen ausgefüllt werden.
|
} // Ende Felder müssen ausgefüllt werden.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($errors != "") echo $errors;
|
if ($errors != "") echo $errors;
|
||||||
Reference in New Issue
Block a user