forked from Hansi132/APP2000
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsjekkUserPass.php
36 lines (33 loc) · 957 Bytes
/
sjekkUserPass.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
<?php
function sjekkUserPass($brukernavn, $passord) {
require_once ("mysqlPDO.php");
try {
$sql = "SELECT epost, fnavn, passord, brukertype FROM bruker WHERE epost = ?;";
$dhn = new mysqlPDO();
$stmt = $dhn->prepare($sql);
$stmt->execute([$brukernavn]);
$result = $stmt->fetch();
function checkBrukertype($brukertype) {
switch ($brukertype) {
case 3:
return "kontrollør";
break;
case 2:
return "administrator";
break;
}
return "bruker";
}
if (strtoupper($result['epost']) == strtoupper($brukernavn) && $result["passord"] == $passord) {
session_start();
$_SESSION["brukernavn"] = $brukernavn;
$_SESSION["brukertype"] = checkBrukertype($result["brukertype"]);
$_SESSION["fnavn"] = $result['fnavn'];
print("<meta http-equiv='refresh' content='0;url=users/backendCheck.php'>");
} else {
print "Wrong username password";
}
} catch (PDOException $e) {
echo $e->getMessage();
}
}