C# Can';我不能让我的不敏感的用户登录功能工作,我做错了什么?沙马林型
我有一个登录功能连接到我的数据库,但我无法让它工作,因为如果我用小写字母(“M”)注册,当我用大写字母(“M”)键入用户名时会出错 您的电子邮件、密码、用户名条目、密码条目=我的xaml文件中的条目 注册表代码:C# Can';我不能让我的不敏感的用户登录功能工作,我做错了什么?沙马林型,c#,xamarin,xamarin.forms,C#,Xamarin,Xamarin.forms,我有一个登录功能连接到我的数据库,但我无法让它工作,因为如果我用小写字母(“M”)注册,当我用大写字母(“M”)键入用户名时会出错 您的电子邮件、密码、用户名条目、密码条目=我的xaml文件中的条目 注册表代码: var userInfo = await parseAPI.signupUser (yourEmail.Text, yourPassword.Text); if (userInfo ["error"] == null) { Application.Current.Proper
var userInfo = await parseAPI.signupUser (yourEmail.Text, yourPassword.Text);
if (userInfo ["error"] == null) {
Application.Current.Properties ["userId"] = userInfo ["objectId"].ToString ();
Application.Current.Properties ["sessionToken"] = userInfo ["sessionToken"].ToString ();
await Application.Current.SavePropertiesAsync ();
} else {
}
还有我的登录码:
var userInfo = await parseAPI.loginUser (usernameEntry.Text, passwordEntry.Text);
if (userInfo ["error"] == null) {
Application.Current.Properties ["userId"] = userInfo ["objectId"].ToString ();
Application.Current.Properties ["sessionToken"] = userInfo ["sessionToken"].ToString ();
await Application.Current.SavePropertiesAsync ();
//loginstrings
String theUserString = usernameEntry.Text.ToUpper ();
String theUserString = passwordEntry.Text.ToUpper ();
//registerstrings
String theUserStringRegister = yourPassword.Text.ToUpper ();
String theUserStringRegister = yourEmail.Text.ToUpper ();
Navigation.PopModalAsync ();
} else {
await DisplayAlert ("Wrong password", "Try again", "Ok");
}
您将用户的输入直接传递给注册和登录函数,而无需修改案例。您需要强制它们使用相同的情况,并在整个代码中一致地使用它们
string userName = yourEmail.Text.ToLower();
// always register the user using the lcase namne
var userInfo = await parseAPI.signupUser (userName, yourPassword.Text);
// then when logging in, always use the lcase name for consistency
var userInfo = await parseAPI.loginUser (userName, passwordEntry.Text);
您也可以对密码执行同样的操作,但使用不区分大小写的密码是非常罕见的—我不建议这样做。您正在登录,然后
ToUpper()
。为什么?您的注册用户
和登录用户
都没有指定任何与大小写无关的内容。除了@Rob的问题,上面的登录代码是否编译?看起来“theUserString”和“theUserStringRegister”声明了两次。是的,它可以工作,但只有在我使用相同的registeredinfo时。因此,如果我注册“m”,我必须在登录时键入“m”,而不是“m”。