简体   繁体   English

登录:区分大小写的Xcode / PHP

[英]Login: Case sensitive Xcode/PHP

I have a problem with Xcode and a customer-login function. 我对Xcode和客户登录功能有疑问。 2 Textfields: One for name and one for password. 2个文本字段:一个用于名称,另一个用于密码。

In my database (for example) the password is "Hello". 例如,在我的数据库中,密码为“ Hello”。 But I can type "Hello" OR "hello" (not case-sensitive) to fulfill the login conditions. 但是我可以键入“ Hello”或“ hello”(不区分大小写)来满足登录条件。

What can i do to make it case-sensitive? 我该怎么做才能区分大小写? (in Xcode or PHP?) (在Xcode或PHP中?)

The .php-file: .php文件:

$Nickname = $_GET["User"];
$Password = $_GET["Password"];


$query = "SELECT Count(*) FROM kunde WHERE Nickname='$Nickname' AND Password='$Password'";

$result=mysql_query($query) or die("error");
    $num = mysql_numrows($result);
    mysql_close();


    $rows = array();
    while ($r = mysql_fetch_assoc($result))
    {
        $rows[] = $r['Count(*)'];

    }
    echo json_encode($rows); 

You should not be storing passwords in plain text. 您不应以纯文本形式存储密码。 Use a hashing function like sha1() with a salt. 使用带有sha的哈希函数(如sha1())。 Your password will be case-sensitive. 您的密码区分大小写。

$Password = sha1($Password . 'somerandomstring');

You need to use it before storing the password and before checking for it. 您需要在存储密码之前和检查密码之前使用它。 sha1() will always generate the same string with the same input. sha1()将始终使用相同的输入生成相同的字符串。

As for other fields in the database, you can make sure they are case sensitive by using an appropriate collation for them. 对于数据库中的其他字段,可以通过使用适当的排序规则来确保它们区分大小写。 Right now you are using utf8_general_ci . 现在,您正在使用utf8_general_ci The 'ci' part at the end stands for case insensititive. 最后的“ ci”部分代表不区分大小写。 Changing it for utf8_general_cs will solve the issue. 更改为utf8_general_cs可以解决此问题。

You can also query the column as binary and it will be case sensitive: 您还可以将列查询为二进制,这将区分大小写:

$query = "SELECT Count(*) FROM kunde WHERE Nickname='$Nickname' AND binary Password='$Password'";

Remember to escape your $Nickname and $Password to avoid [sql injection][1]. 请记住转义您的$ Nickname和$ Password以避免[sql injection] [1]。 (http://en.wikipedia.org/wiki/SQL_injection) (http://zh.wikipedia.org/wiki/SQL_injection)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM