2012-11-02 5 views
0

내 사용자 등록 스크립트에 약간의 문제가 있습니다. 어떤 이유에서든 양식 필드 pass1과 pass2가 코드, 아이디어에 관계없이 동일한 지 확인하지 않으십니까? 귀하의 검토를 위해 아래에 전체 등록 코드를 기입하겠습니다. 나는 PHP에 아주 익숙해 져서 어떤 조언을 주시면 감사하겠습니다. 도움을 주셔서 감사합니다. :-)비밀 번호를 확인하지 않는 사용자 스크립트 등록

등록 스크립트.

<?php 
ob_start(); // Start output buffering 

function isLoggedIn() 
{ 
    if(isset($_SESSION['valid']) && $_SESSION['valid']) 
     return true; 
    return false; 
} 


session_start(); 
//if the user has not logged in 
if(!isLoggedIn()) 
{ 
    header('Location: ../index.php'); 

    die(); 
} 


?> 
<?php require_once('../Connections/PropSuite.php'); ?> 

<?php 

error_reporting(E_ALL & ~E_NOTICE); 
ini_set('display_errors', TRUE); 
ini_set('display_startup_errors', TRUE); 

if (!function_exists("GetSQLValueString")) { 
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{ 
    if (PHP_VERSION < 6) { 
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; 
    } 

    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); 

    switch ($theType) { 
    case "text": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break;  
    case "long": 
    case "int": 
     $theValue = ($theValue != "") ? intval($theValue) : "NULL"; 
     break; 
    case "double": 
     $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; 
     break; 
    case "date": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break; 
    case "defined": 
     $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; 
     break; 
    } 
    return $theValue; 
} 
} 

$colname_user = "-1"; 
if (isset($_SESSION['username'])) { 
    $colname_user = $_SESSION['username']; 
} 
mysql_select_db($database_Takeaway, $Takeaway); 
$query_user = sprintf("SELECT type FROM admin_users WHERE username = %s", GetSQLValueString($colname_user, "text")); 
$user = mysql_query($query_user, $Takeaway) or die(mysql_error()); 
$row_user = mysql_fetch_assoc($user); 
$totalRows_user = mysql_num_rows($user); 






    // Username available. 


//form begins 
$user_type = $row_user['type']; 

    if ($user_type === 'admin-full') 
    { 
//retrieve our data from POST 
$name = $_POST['name']; 
$username = $_POST['username']; 
$email = $_POST['email']; 
$pass1 = $_POST['pass1']; 
$pass2 = $_POST['pass2']; 
if($pass1 != $pass2) 
    header('Location: register-admin.php?pw=notmatched'); 
if(strlen($username) > 30) 
    header('Location: register-admin.php?username=toolong'); 
if(strlen($name) > 40) 
    header('Location: register-admin.php?name=toolong'); 

$hash = hash('sha256', $pass1); 

//creates a 3 character sequence 
function createSalt() 
{ 
    $string = md5(uniqid(rand(), true)); 
    return substr($string, 0, 3); 
} 
$salt = createSalt(); 
$hash = hash('sha256', $salt . $hash); 


mysql_select_db($database_Takeaway, $Takeaway); 
//sanitize username 
$username = mysql_real_escape_string($username); 

$q = "SELECT id, username FROM admin_users WHERE username = '$username'"; 
$results = @mysql_query($q); 
if(mysql_num_rows($results) > 0) 
{ 
    // Username exists. 
header('Location: register-admin.php?username-taken'); 
} 
else 
{ 


$query = "INSERT INTO admin_users (type, email, name, username, password, salt) 
     VALUES ('admin-full', '$email', '$name', '$username' , '$hash' , '$salt');"; 
mysql_query($query); 
mysql_close(); 
header('Location: ../main?NewUserAdded'); 
} 

mysql_free_result($user); 
    } 
    else { 
?> 
You are not authorised to do that! 
<?php } ?> 

UPDATE

양식 코드는 스크립트가 다르게 실행 유지하고 당신이 다른 헤더를 설정하기 때문에

<form name="register" action="register-admin1.php" method="post"> 
    <?php if (isset($_REQUEST["username-taken"])) { ?> 
     <p style="color: #F00">Username already exists! please try again</p> 
     <?php } ?> 
     <?php if (isset($_REQUEST["pw=notmatched"])) { ?> 
     <p style="color: #F00">Username already exists! please try again</p> 
     <?php } ?> 
    <p>Register New Admin User<br /> 
     (Note! Admin users are top level and will have access to everything!) 
     <br /> 
    </p> 
     <p>Name: 
     <input name="name" type="text" id="name" maxlength="30" /> 
     </p> 
     <p>Email: 
     <input name="email" type="text" id="email" maxlength="30" /> 
     </p> 
     <p>Username: 
     <input type="text" name="username" maxlength="30" /> 
     </p> 
     <p> 
     Password: 
      <input type="password" name="pass1" /> 
     </p> 
     <p>Password Again: 
     <input type="password" name="pass2" /> 
    </p> 
     <p> 
     <input type="submit" value="Register" /> 
     </p> 
    </form> 
+0

양식은 어디에 있습니까? –

+0

'GetSQLValueString' 함수는 절대적으로 무서운 것입니다. [적절한 SQL 탈출] (http://bobby-tables.com/php)에 대한 무분별한 경시를 혼란스럽게하는 것 이외에 어떤 목적이 있습니까? – tadman

답변

1

header('Location: register-admin.php?pw=notmatched');die();을 넣어이다. 그래서 같이

는 :

if($pass1 != $pass2) { 
    header('Location: register-admin.php?pw=notmatched'); 
    die(); 
} 
if(strlen($username) > 30) { 
    header('Location: register-admin.php?username=toolong'); 
    die(); 
} 
if(strlen($name) > 40) { 
    header('Location: register-admin.php?name=toolong'); 
    die(); 
} 
+0

도움을 주셔서 감사합니다 .--) – AppleTattooGuy

1

당신이 사용자에 대한 정보를 얻기 위해 데이터베이스를 조회하는 경우 사용자 이름 값이 시점에서 세션에있을 것으로 예상된다 것으로 보인다. 폼을 게시하는 경우 세션에서 사용자 이름이 어떻게 될지 이해할 수 없습니다. 귀하의 조건부

아직 게시물 배열에서 사용자 이름을 가져 오지 않고 평가 한 것처럼 절대로 평가하지 않는 것처럼 보입니다.

참고 : mysql_* 함수 대신 mysqli 또는 PDO을 사용해야합니다. PHP에서는 더 이상 사용되지 않습니다.

+0

안녕하십니까, 예, admin 사용자가 다른 관리 사용자를 추가하여 전체 관리자 계정을 가진 사람에게만 페이지에 대한 액세스 권한을 부여해야합니다. – AppleTattooGuy

관련 문제