Symfony2中不区分大小写的用户名 [英] Case-insensitive user-names in Symfony2

查看:66
本文介绍了Symfony2中不区分大小写的用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,Symfony2区分大小写地匹配用户名。我希望用户能够输入 johnsmith JohnSmith johnSMITH 或任何其他变体,并将它们全部注册为约翰·史密斯。我该怎么做?

By default, Symfony2 matches usernames case-sensitively. I want users to be able to enter johnsmith, JohnSmith, johnSMITH, or any variant of that, and have them all register as johnsmith. How do I do this?

我虽然最简单的方法是在比较用户名之前始终将其转换为小写。一方面,这很容易做到(只需将 lower()放入SQL语句中),但是对于用户在登录名中键入的内容,我该怎么做形成?由于Symfony自动处理 login_check 路由处理,因此我无法弄清楚。

I though the easiest way would be to always convert each username to lower-case before comparing them. This is easy to do on the one side (just throw a lower() into the SQL statement), but how do I do that for what the user types in in the login form? Since Symfony automatically takes care of the login_check route handling, I can't figure it out.

更好的是,我可以设置一些选项来启用不区分大小写吗?

Better yet, is there some option I can set to enable case-insensitivity instead?

推荐答案

我觉得自己是个白痴。我要做的就是在SQL语句的 where 子句周围添加另一个 lower()。像这样:

I feel like an idiot. All I had to do was add another lower() around the where clause in my SQL statement. Like this:

select lower(USERNAME) as USERNAME, PASSWORD, ROLES, ALL_CUSTOMER_ACCESS
from COMPANYNAME_USERS
where lower(USERNAME) = lower(:username)

这篇关于Symfony2中不区分大小写的用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆