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
37
38
39
40
41
42
43
44
45
46
47
48
|
<?php include 'config.php';
// Check if the user is logged in
if ((!isSet($_SESSION['loginname'])) || ($loggin <> '1')) { header("Location: login.php"); exit; }
require("configure.php"); require_once 'function_auth.php';
$strength = Password::strength($_POST["loginpw"], $_POST["username"]); if (!$strength) { exit('Insufficient password strength'); } $loginpw = Password::hash($_POST["loginpw"]); $nowdate = date("Y-m-d H:i:s"); //print_r($_POST);
$sth1 = $dbh->prepare("SELECT * FROM sys_cms_login where cmsloginname = ?"); //$sth1->execute(array($_POST["loginname"])); if (!$sth1->execute(array($_POST["loginname"]))) throw new Exception('[' . $sth1->errorCode() . ']: ' . $sth1->errorInfo());
if ($sth1->fetchColumn() > 0) { header("Location: sys_cms_user_index.php?msg=You have already been assigned a login name. "); exit; }
$sth2 = $dbh->prepare("select max(cmsloginid) as maxid from sys_cms_login "); $sth2->execute(); $row2 = $sth2->fetch(PDO::FETCH_ASSOC);
$loginid = $row2{"maxid"} + 1;
$sth3 = $dbh->prepare("insert into sys_cms_login (cmsloginid, cmsusername, cmsloginname, cmsloginpw, cmsrole, cmsstatus, createdate, lastupdate) values (?, ?, ?, ?, ?, ?, ?, ?)"); //$sth3->execute(array($loginid, $_POST["username"], $_POST["loginname"], $loginpw, $_POST["role"], "1", $nowdate, $nowdate));
if (!$sth3->execute(array($loginid, $_POST["username"], $_POST["loginname"], $loginpw, $_POST["role"], "1", $nowdate, $nowdate))) throw new Exception('[' . $sth3->errorCode() . ']: ' . $sth3->errorInfo());
$dbh = null;
header("Location: sys_cms_user_index.php?msg=Add Successfully"); ?>
|