ログインフォームを開発しました。
これは私のWebサービスコードです:
public class Login {
public String authentication(String userName,String password){
String retrievedUserName = "";
String retrievedPassword = "";
String status = "";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/androidlogin","root","chathura");
PreparedStatement statement = con.prepareStatement("SELECT * FROM user WHERE username = '"+userName+"'");
ResultSet result = statement.executeQuery();
while(result.next()){
retrievedUserName = result.getString("username");
retrievedPassword = result.getString("password");
}
if(retrievedUserName.equals(userName)&&retrievedPassword.equals(password)){
status = "Success!";
}
else{
status = "Login fail!!!";
}
}
catch(Exception e){
e.printStackTrace();
}
return status;
}
}
これは私のアンドロイドコードです:
try{
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
String status = response.toString();
TextView result = (TextView) findViewById(R.id.tv_status);
result.setText(response.toString());
if(status.equals("Success!")){
// ADD to save and read next time
String strUserName = userName.getText().toString().trim();
String strPassword = userPassword.getText().toString().trim();
if (null == strUserName || strUserName.length() == 0){
// showToast("Enter Your Name");
userName.setError( "username is required!" );
isUserValidated = false;
}
if (null == strPassword || strPassword.length() == 0){
// showToast("Enter Your Password");
isPasswordValidated = false;
userPassword.setError( "password is required!" );
}
if(isUserValidated && isPasswordValidated){
Intent intent = new Intent(AndroidLoginExampleActivity.this,TabBarSimple.class);
intent.putExtra("login",userName.getText().toString());
startActivity(intent);
}
}
else{
Intent i = new Intent(getApplicationContext(), AndroidLoginExampleActivity.class);
startActivity(i);
}
}
catch(Exception e){
//
}
}
}
私の現在のo / pは次のとおりです。
正しいログインの詳細を入力すると、「成功」メッセージが表示され、その後次のアクティビティに進みます
間違ったログイン情報を入力すると、「ログインに失敗しました」というメッセージが表示されます。
o / pが必要な場合は次のとおりです。
正しいログインの詳細を入力すると、次のアクティビティに直接移動し、成功メッセージは表示されません。
間違ったログイン情報を入力すると、「ログインに失敗しました」というメッセージが表示されます。
これで私を助けてください。どうすればこれを開発できますか?