本文介绍了用大写和小写字母验证用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户在我的asp.net成员数据库中注册了名称"Mike".现在,当用户尝试使用"mike"登录时,它正在登录.我的问题是在重串时,用户使用大写字母"M"输入,而在使用小写字母登录时,它正在登录.他的要求是仅使用他给的字符...像迈克"而不是迈克".请帮帮我...

I have a user who registered with the name "Mike" in my asp.net membership database. Now when the user trying to login with "mike" it is loging in. My question is while restring, user gave "M" as capital letter and while loging in with lowercase letter it is loging in. His requirement is to login with only the characters which he has given... like "Mike" not "mike". Please help me out ...

推荐答案

SELECT myColumn FROM myTable
    WHERE myColumn COLLATE Latin1_General_CS_AS = 'caSE'



通过执行区分大小写的SQL查询,仅精确匹配将重新调整,即将不返回"mike",但将返回"Mike".

进一步的方法,
我将使用字符串比较方法为您提供另一种解决方案,只要您检查/比较字符串



By performing case sensitive SQL query, only the exact match will retun, that is "mike" will not be returned but "Mike" will be returned.

Further approaches,
I will give you another solution with using string comparison method, Whenever you check/compare the string

string database_username = "Mike";
            string input_username = "mike";

            //this will perform a case sensitive comparison
            input_username.Equals(database_username, StringComparison.Ordinal);

            //this comparison will ignore case. Hence not suitable for your scenario
            input_username.Equals(database_username, StringComparison.OrdinalIgnoreCase);



另一种方法是使用正则表达式.使用数据库中的用户名检查输入的用户名时,请使用正则表达式.

另外,您也可以使用RegularExpressionValidator类
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.regularexpressionvalidator.aspx [ ^ ]

最后,花一些时间搜索&研究中,有很多资源.

谢谢



Another approach is to use Regular expressions. When you check the input username with the username in database, use with regular expressions.

Alternatively you also can use RegularExpressionValidator class
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.regularexpressionvalidator.aspx[^]

At last, Spend some time in searching & researching, there are plenty of resources.

Thanks


select BINARY_CHECKSUM('abc') --result 26435
select BINARY_CHECKSUM('Abc') --result 18243


select BINARY_CHECKSUM('aA') --result 1617
select BINARY_CHECKSUM('Aa') --result 1137



祝您编码愉快!
:)



Happy Coding!
:)


//COLLATE Latin1_general_CS_AS  this line is used to check case sensitive of characters that is it in upper case or lower case ?

adp = new SqlDataAdapter("select uname,upass from tblogin where uname COLLATE Latin1_general_CS_AS =@uname and upass COLLATE Latin1_general_CS_AS =@upass", con);


这篇关于用大写和小写字母验证用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 02:30