gpt4 book ai didi

ios - 用户登录使用 XCode ios

转载 作者:行者123 更新时间:2023-11-28 22:35:04 25 4
gpt4 key购买 nike

我有两个 View Controller (view1 和 view2(比方说))。在 view1 中,我有用于输入用户名和密码的文本字段,以及一个登录按钮。按登录后,用户应该能够推送到 view2(如果用户名和密码已从数据库中验证)。我添加了以下方法,单击登录时将调用该方法:

-(IBAction)clickButton:(id)sender
{ const char *dbpath = [mDatabasePath UTF8String];
sqlite3_stmt *statement;
if (sqlite3_open(dbpath, &mDiary) == SQLITE_OK)
{
NSString *querySQL = [NSString stringWithFormat: @"SELECT *FROM USERDETAIL"];
const char *query_stmt = [querySQL UTF8String];
if (sqlite3_prepare_v2(mDiary,
query_stmt, -1, &statement, NULL) == SQLITE_OK)
{
if (sqlite3_step(statement) == SQLITE_ROW)
{
Gusr = [[NSString alloc]
initWithUTF8String:
(const char *) sqlite3_column_text(statement, 0)];
Gpass = [[NSString alloc]
initWithUTF8String:
(const char *) sqlite3_column_text(statement, 1)];

NSLog(@"%@ %@",Gusr,Gpass);
NSLog(@"%@ %@",mUserName.text,mPassword.text);
if (!([mUserName.text isEqualToString:Gusr] && [mPassword.text isEqualToString:Gpass])){

NSLog(@"Invalid credentials");
mUserName.text = @"";
mPassword.text = @"";
// [self performSegueWithIdentifier:@"Login" sender:self];
}else {

}

}



}
sqlite3_finalize(statement);

}
sqlite3_close(mDiary);
}

问题是用户可以使用任何凭据登录。 Gusr 和 Gpass 正在日志中打印。我还应该在这里提到 view1 和 view2 具有相同的自定义类。(我正在使用 Storyboard)

OK 将它添加到 else 部分使其工作:

VIewControllerName *obj = [storyboard instantiateViewControllerWithIdentifier:@"ViewController_storyBoardId"];
[self.navigationController pushViewController:obj animated:YES];

感谢 Kumar.. :)

最佳答案

像这样尝试:

if ([mUserName.text isEqualToString:Gusr] && [mPassword.text isEqualToString:Gpass]){


UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
VIewControllerName *obj = [storyboard instantiateViewControllerWithIdentifier:@"ViewController_storyBoardId"];

[self.navigationController pushViewController:obj animated:YES]; // This is using by navigation controller , Are You using it?



}else {

NSLog(@"Invalid credentials");
mUserName.text = @"";
mPassword.text = @"";
}

关于ios - 用户登录使用 XCode ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16317679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com