usingUnityEngine;
usingSystem.Collections;
usingUnityEngine.UI;
usingMono.Data.Sqlite;
publicclassLoginScript:MonoBehaviour{
public InputField accountText;
public InputField passwordText;
Text showText;
SqliteConnection connection;
SqliteCommand command;
SqliteDataReader reader;
string dbPath;
voidStart( ){
showText=GameObject.Find("ShowText").GetComponent<Text>( );
dbPath="DataSource="+Application.streamingAssetsPath+"/UserDatabase.sqlite";
connection=new SqliteConnection(dbPath);
connection.Open( );
command=connection.CreateCommand( );
}
publicvoidButtonPressed( ){
Login( );
}
public void ButtonPressed_1( ){
Reset( );
}
public void ButtonPressed_2( ){
Registered( );
print("sfd");
}
public void Login( ){
string account=accountText.text;
string password=passwordText.text;
if(account.Length>0&&password.Length>0){
//找到与数据库中与account相同的uname
command.CommandText="SELECT*FROM UserTable WHERE uname="+"'"+account+"'";
object obj=command.ExecuteScalar( );
if(obj!=null){
if(password==obj.ToString()){
print("sdf");
showText.text="登陆成功";
}else{
showText.text="密码错误";
}
}else{
showText.text="用户名不存在";
}
}
}
voidReset( ){
accountText.text="";
passwordText.text="";
showText.text="";
command.CommandText="DELETE FROM UserTable WHERE rowid>0";
try{
command.ExecuteNonQuery();
}catch(SqliteExceptionex){
print(ex.Message);
}
}
voidRegistered( ){
command.CommandText="INSERTINTOUserTable(pwd,uname)VALUES("+"'"+passwordText.text+"'"+","+"'"+accountText.text+"'"+")";
command.ExecuteNonQuery( );
print("5612");
}
}