English 中文(简体)
用户投入使用白色清单
原标题:Using a whitelist on user input

我有使用用户名和密码的简单格式。 我想申请一个白色名单,只允许某些特性。 我有意知道任何人是否需要这样做,但这里是检索用户名和密码的代码:

$stmt = $conn2->prepare("SELECT username FROM users WHERE username = ? AND password = ?");

$stmt->bind_param("ss", $username, $password);      
$stmt->execute();
$stmt->store_result();

我也这样做:

preg_replace( "/[^a-zA-Z0-9_]/", "", $stringToFilter );

如果是的话,我是在什么地方把它列入我的法典? 如果用户试图提供除白名单上的内容以外的内容,会发生什么情况?

ADDED: 是否在登记期间使用INSERT储存用户名和密码?

//insert data
$stmt = $conn2->prepare("INSERT INTO users (username, email, password) VALUES (?, ?, ?)");

//bind the parameters
$stmt->bind_param( sss , $username, $email, $password);
最佳回答

在登记期间,在<代码>INSERT之前添加过滤代码。 检查测验在过滤后没有空洞,因此,没有插入“密码”的用户名!

$username_clean = preg_replace( "/[^a-zA-Z0-9_]/", "", $_POST[ username ] );

if (!strlen($username_clean)){

    die("username is blank!");
}

$stmt = $conn2->prepare("INSERT INTO users (username, email, password) VALUES (?, ?, ?)");
$stmt->bind_param( sss , $username_clean, $email_clean, $password_clean);
问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签