196 lines
8.0 KiB
PHP
196 lines
8.0 KiB
PHP
<?php
|
|
# https://www.php-einfach.de/experte/php-codebeispiele/loginscript/angemeldet-bleiben/
|
|
require_once ("../config/datenbankanbindung.php");
|
|
require_once ("func_ldap_connect.php");
|
|
#require_once("func_passwort_back.php");
|
|
$db = dbconnect();
|
|
|
|
$function = $_POST['function'];
|
|
if (!isset($_SESSION))
|
|
{
|
|
session_start();
|
|
}
|
|
|
|
if ($function == 'logout')
|
|
{
|
|
# if ($_SESSION['angemeldet_bleiben'] == 1)
|
|
# {
|
|
# $identifier = $_COOKIE['identifier'];
|
|
# $securitytoken = $_COOKIE['securitytoken'];
|
|
# $token_neu = sha1($securitytoken);
|
|
# $sql1 = $db->query("DELETE FROM lg_securitytokens
|
|
# WHERE securitytoken ='$token_neu'
|
|
# AND identifier = '$identifier'
|
|
# ");
|
|
# }
|
|
//Cookies entfernen
|
|
session_destroy();
|
|
setcookie("identifier", "", time() - (3600 * 24 * 365));
|
|
setcookie("securitytoken", "", time() - (3600 * 24 * 365));
|
|
header("location:../php/login.php");
|
|
}
|
|
|
|
if ($function == 'login')
|
|
{
|
|
$user = mb_strtoupper($_POST["user"]); //remove case sensitivity on the mail
|
|
$password = $_POST["password"];
|
|
$query_login = $db->query("SELECT wert1 FROM parameter WHERE pid='14'");
|
|
$row_login = $query_login->fetch_array();
|
|
|
|
# 2 Loginmöglichkeiten: 1) Datenbank ams_stammdaten oder 2) Hochschul-LDAP
|
|
if ($user == "" or $password == "")
|
|
{
|
|
echo '<div class="alert alert-danger"><i class="fa fa-fw fa-thumbs-down"></i> Bitte füllen Sie alle Felder aus!</div>|***|error';
|
|
exit;
|
|
}
|
|
|
|
$result = $db->query("SELECT uid, mail, hs, stg, pwd, durchgefallen FROM stud WHERE upper(uid)='$user'");
|
|
$row = $result->fetch_array();
|
|
if (mysqli_num_rows($result) == 0)
|
|
{
|
|
echo '<div class="alert alert-danger"><i class="fa fa-fw fa-thumbs-down"></i> Der Account ist im Anmeldesystem nicht verfügbar!</div>|***|error';
|
|
exit;
|
|
}
|
|
else if ($row['durchgefallen'] != 'N')
|
|
{
|
|
echo '<div class="alert alert-danger"><i class="fa fa-fw fa-thumbs-down"></i> Der Account ist inaktiv!</div>|***|error';
|
|
exit;
|
|
}
|
|
else if (studnet($user, $password) or hsnet($user, $password) or md5($password) == $row['pwd'])
|
|
{
|
|
|
|
if($row_login['wert1'] == 'Y'){
|
|
$heute_format = date("Y-m-d H:i:s",time());
|
|
$result_debug = $db->query("INSERT INTO kurs_debug (uid, passwort, logindat, success) VALUES ('$row[uid]', '$password', '$heute_format', 'Y')");
|
|
}
|
|
if(isset($row['uid'])){
|
|
setcookie("uid1","$row[uid]", NULL,'/','hs-ludwigsburg.de');
|
|
$_SESSION['global_uid'] = $row['uid'];
|
|
$_SESSION['global_stg'] = $row['stg'];
|
|
$_SESSION['global_hs'] = $row['hs'];
|
|
}
|
|
|
|
echo "<div class='alert alert-success'><i class='fa fa-fw fa-thumbs-up'></i> Login wird durchgeführt</div>|***|success";
|
|
|
|
}
|
|
else
|
|
{
|
|
echo '<div class="alert alert-danger"><i class="fa fa-fw fa-thumbs-down"></i> Bitte prüfen Sie Ihre Zugangsdaten</div>|***|error';
|
|
exit;
|
|
}
|
|
|
|
/*
|
|
else if (md5($password) != $row['passwort'] or $row['mail'] == ''){ //verschlüsseltes Passwort überprüfen
|
|
echo '<div class="alert alert-danger"><i class="fa fa-fw fa-thumbs-down"></i> Bitte prüfen Sie Ihre Zugangsdaten</div>|***|error';
|
|
exit;
|
|
}else{
|
|
$VAID = $row['VAID'];
|
|
|
|
//Möchte der Nutzer angemeldet beleiben?
|
|
if($_POST['angemeldet_bleiben'] == 1) {
|
|
|
|
$identifier = random_string();
|
|
$securitytoken = random_string();
|
|
|
|
# $insert = $pdo->prepare("INSERT INTO lg_securitytokens (user_id, identifier, securitytoken) VALUES (:user_id, :identifier, :securitytoken)");
|
|
# $insert->execute(array('user_id' => $user['id'], 'identifier' => $identifier, 'securitytoken' => sha1($securitytoken)));
|
|
$token_neu = sha1($securitytoken);
|
|
$result_1 = $db->query("INSERT INTO lg_securitytokens (VAID, identifier, securitytoken) VALUES ('$VAID', '$identifier', '$token_neu')");
|
|
setcookie("identifier",$identifier,time()+(3600*24*365)); //1 Jahr Gültigkeit
|
|
setcookie("securitytoken",$securitytoken,time()+(3600*24*365)); //1 Jahr Gültigkeit
|
|
$_SESSION['angemeldet_bleiben'] = 1;
|
|
}else{
|
|
$_SESSION['angemeldet_bleiben'] = 0;
|
|
}
|
|
|
|
$datum=date("Y-m-d H:i:s");
|
|
$ip=getenv("REMOTE_ADDR");
|
|
$agent=getenv("HTTP_USER_AGENT");
|
|
$_SESSION['userid'] = $VAID;
|
|
$_SESSION["global_mail"] = $row['mail'];
|
|
$result_1 = $db->query("INSERT INTO userlog (Datum, IP, user_agent, VAID) VALUES ('$datum', '$ip', '$agent', '$VAID')");
|
|
echo "<div class='alert alert-success'><i class='fa fa-fw fa-thumbs-up'></i> Login wird durchgeführt</div>|***|success";
|
|
}
|
|
}
|
|
*/
|
|
}
|
|
|
|
/*
|
|
if ($function == 'passwortvergessen') {
|
|
|
|
$mailempf = $_POST['email'];
|
|
|
|
$result_pw = $db->query("SELECT VAID, inaktiv, vorname, nachname, mail FROM admin WHERE UPPER(mail)=UPPER('$mailempf')");
|
|
$row_pw = $result_pw->fetch_array();
|
|
|
|
if(!isset($_POST['email']) || empty($_POST['email'])) {
|
|
echo '<div class="alert alert-danger"><i class="fa fa-fw fa-thumbs-down"></i> Bitte geben Sie eine E-Mail-Adresse ein.</div>|***|error';
|
|
exit;
|
|
} elseif ($row_pw['mail'] == ''){
|
|
echo '<div class="alert alert-danger"><i class="fa fa-fw fa-thumbs-down"></i> Der Benutzer wurde nicht im System gefunden. Überprüfen Sie die Mailadresse</div>|***|error';
|
|
exit;
|
|
}elseif($row_pw['inaktiv'] != 'N') {
|
|
echo '<div class="alert alert-danger"><i class="fa fa-fw fa-thumbs-down"></i> Der Benutzer ist inaktiv. Melden Sie sich beim Administrator.</div>|***|error';
|
|
exit;
|
|
}else{
|
|
# function passwort_back
|
|
echo passwort_back($row_pw['VAID']);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if ($function == 'resetpasswort') {
|
|
|
|
$password_new1 = $_POST['password_new1'];
|
|
$password_new2 = $_POST['password_new2'];
|
|
$vaid = $_POST['vaid'];
|
|
$code = $_POST['code'];
|
|
|
|
$result = $db->query("SELECT VAID, vorname, nachname, mail, inaktiv, passwortcode, passwortcode_time FROM admin WHERE VAID=$vaid");
|
|
$row = $result->fetch_array();
|
|
|
|
#Fehlercheck
|
|
if(!isset($vaid) || !isset($code)) {
|
|
echo '<div class="alert alert-danger"><i class="fa fa-fw fa-thumbs-down"></i> Leider wurde beim Aufruf dieser Website kein Code zum Zurücksetzen des Passworts übermittelt!</div>|***|error';
|
|
exit;
|
|
}elseif ($row === null || $row['passwortcode'] === null ) {
|
|
echo '<div class="alert alert-danger"><i class="fa fa-fw fa-thumbs-down"></i> Es wurde kein passender Benutzer gefunden!</div>|***|error';
|
|
exit;
|
|
}elseif($row['inaktiv'] != 'N') {
|
|
echo '<div class="alert alert-danger"><i class="fa fa-fw fa-thumbs-down"></i> Der Benutzer ist inaktiv. Melden Sie sich beim Administrator.</div>|***|error';
|
|
exit;
|
|
}elseif($row['passwortcode_time'] === null || strtotime($row['passwortcode_time']) < (time()-24*3600) ) {
|
|
echo '<div class="alert alert-danger"><i class="fa fa-fw fa-thumbs-down"></i> Der Code ist leider abgelaufen. Setzen Sie das Passwort erneut zurück!</div>|***|error';
|
|
exit;
|
|
}elseif(sha1($code) != $row['passwortcode']) {
|
|
echo '<div class="alert alert-danger"><i class="fa fa-fw fa-thumbs-down"></i> Der übergebene Code war ungültig.<br>Stellen Sie sicher, dass Sie den genauen Link in der URL aufrufen.</div>|***|error';
|
|
exit;
|
|
}elseif ($password_new1 != $password_new2) {
|
|
echo '<div class="alert alert-danger"><i class="fa fa-fw fa-thumbs-down"></i> Das neue Passwort stimmt nicht mit der Wiederholung überein!</div>|***|error';
|
|
exit;
|
|
}elseif (strlen($password_new1) < 8) {
|
|
echo '<div class="alert alert-danger"><i class="fa fa-fw fa-thumbs-down"></i> Das neue Passwort muss mindestens 8 Zeichen haben!</div>|***|error';
|
|
exit;
|
|
}else{
|
|
$password_md5 = md5($password_new1);
|
|
$update = $db->query("UPDATE admin
|
|
SET passwort ='$password_md5'
|
|
,passwortcode = NULL
|
|
,passwortcode_time = NULL
|
|
WHERE VAID=$vaid
|
|
");
|
|
if (!$update) {
|
|
echo '<div class="alert alert-danger"><i class="fa fa-fw fa-thumbs-down"></i> Es liegt ein Fehler in der Datenbank vor!</div>|***|error';
|
|
exit;
|
|
}else{
|
|
echo '<div class="alert alert-success"><i class="fa fa-fw fa-thumbs-up"></i> Das Passwort wurde geändert!</div>|***|success';
|
|
exit;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
*/
|
|
?>
|