Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在MySQL PHP中使用URL识别和激活用户的一种足够安全的方法_Php_Mysql - Fatal编程技术网

在MySQL PHP中使用URL识别和激活用户的一种足够安全的方法

在MySQL PHP中使用URL识别和激活用户的一种足够安全的方法,php,mysql,Php,Mysql,使用用户电子邮件和专用散列检查我的表是否足以验证和激活帐户(如果发现这两个值匹配) 用户被要求使用用户数据和他们的电子邮件id注册自己。然后,他们会被发送一个URL到他们的电子邮件,并被要求单击以确认和激活他们的帐户 这是我当前的设置: <?php //The user-account-creation processing page $email_id = taken from user input; $randomnessWhateverItsCalled = "lo

使用
用户电子邮件和专用
散列检查我的表是否足以验证和激活帐户(如果发现这两个值匹配)

用户被要求使用用户数据和他们的电子邮件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
?>

只要你让“随机性”部分难以猜测,它看起来就足够安全了。你可以把电子邮件、用户名、密码等放在那里,然后把它们和另一个密钥混在一起——全部加密——这就是我通常做的


但是我建议您将0/1用于活动/非活动-为什么要使用字符串,当您可以对smallint(1)执行相同操作时-并节省一些空间,从而使数据库更轻一些?

而我同意
布尔值
tinyint(1)
更适合用作活动/非活动标志我不完全同意其原因。最好使用表达性、易于理解的“标准”结构,因为它有助于形式和功能的可预测性。这意味着一个名为
status
的布尔字段将很容易理解,无需进一步的文档。为什么不呢?数据库上的空间更少,搜索/排序速度更快?节省几个字节(虽然是件好事)远没有十年前那么必要。我绝不会容忍(ab)使用空间——恰恰相反,如果你能节省一些空间,这意味着你的索引/键也会读得更快。但是,如果从
varchar'yes'
boolean true
保存2个字节,索引的差异是不可测量的(包括大小和速度),与可用空间相比,实际磁盘空间的差异可以忽略不计。但真正的差异是int(10)与bigint(20)与uuid标识符列之间的差异,大(索引)varchar列,大型(全文索引)文本列。因为这些会严重影响磁盘大小、索引大小、搜索速度、交叉点/连接速度等。请阅读相关内容,了解安全标准,甚至可能使用现成的库。@MihaiStancu,您好,你能解释一下你的评论是如何回答我的问题的吗?Pavan我的回答不是一个答案,而是一个能够完美解释为什么它不能回答问题的评论。评论用于附带(相关)信息(请求和提供)。我只是给你提供一些辅助阅读材料。
<?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.
        }
        */

?>