URL이

2014-09-10 2 views
0

인 MySQL PHP 사용자를 식별하고 활성화하는 데 충분한 보안 방법 user's emailhash 전용 테이블에서이 두 값과 일치하는 항목이 발견되면 계정을 확인하고 활성화 할 수 있습니까?URL이

사용자에게 사용자 데이터와 이메일 ID를 등록하라는 메시지가 표시됩니다. 그런 다음 이메일에 URL이 전송되어 클릭하여 계정을 확인하고 활성화합니다.

이 내 현재 설정입니다 :

<?php //The user-account-creation processing page 

    $email_id = taken from user input; 
    $randomnessWhateverItsCalled = "lots-of-randomness-here"; 

    UPDATE advert SET advert_hash = SHA1(CONCAT($email_id, $randomnessWhateverItsCalled)) 

    //For simplicity's sake I omitted the PDO stuff 
    INSERT INTO table_name (..., user_email, hash, account_activated, ...) VALUES (..., usersEmail, advert_hash, NO, ...) 


    /** 
     Send an email with some php code with the URL that would look like this 
     URL to click on attached to email body: 
    */ 
    $attachStringToEmailBody = "http://www.domainname.com/activate-user?email_id=" . $usersEmail . "&hash=" . $randomnessWhateverItsCalled; 
enter code here 

    //Send email from this process page with a little email php code 

    //Redirect user to a page informing the user to activate the account by visiting their email and clicking on the url 
?> 

그런 다음 activate-user.php 페이지에서 나는 다음과 같은 한 :

<?ph 
    $user_email = $_GET['email_id']; 
    $hash = $_GET['hash']; 


    /** 
     search database and return a row if there is a match containing both the $user_email and the $hash 
     if(match){ 
      Update database and set the `account_activated` column to `YES` 
     } 
     else{ 
      //Tell if there was no match then activation failed 

      //Let the user know that we do not recognise the link they used to try and activate their account. 
     } 
     */ 

?> 
+0

[PHPass] (http://www.openwall.com/phpass/)에서 보안 표준에 대한 아이디어를 얻으십시오. 기성품 라이브러리를 사용해보십시오. –

+0

@MihaiStancu, 안녕하세요, 귀하의 의견이 내 질문에 어떻게 대답하는지 설명해 주시겠습니까? – Pavan

+0

Pavan 제 대답은 대답이 아닙니다. 질문에 대답하지 않는 이유를 완벽하게 설명하는 설명입니다. –

답변

0

그것은 오래 당신이 "임의성"부분을 열심히 만들어으로, 충분한 보안 보인다 추측합니다. 전자 메일, 사용자 이름, 암호 등을 넣고 다른 키 (모두 암호화 됨)를 넣을 수 있습니다. 일반적으로 그렇게합니다.

활성/비활성 - smallint (1)을 사용하여 동일한 작업을 수행 할 수있는 이유는 무엇입니까? - 그리고 약간의 공간을 절약 할 수 있도록 데이터베이스를 약간 더 가볍게 만드는 것이 좋습니다.

+0

나는'boolean' 또는'tinyint (1)'이 활성/비활성 플래그로 사용하기에 훨씬 더 적절하다는 것에 동의하지만 나는 그 이유에 완전히 동의하지 않는다. –

+0

표현과 이해하기 쉬운 "표준"구조를 사용하는 것이 형식과 기능의 예측 가능성을 높이는 데 도움이되므로 항상 사용하는 것이 좋습니다. '상태'라는 부울 필드가 더 이상의 문서없이 이해하기 쉽다는 것을 의미합니다. –

+0

왜 안 되니? 그것은 데이터베이스의 공간이 적어 검색/정렬이 빠릅니다. – mariobgr