To execute user authentication with password change on mobile platform server, create the AuthWithChangePassword application that uses framework methods:
Method name | Brief description |
authWithChangePassword | The method replaces the current password with a new one. |
auth | The method checks if general user authorization works well. |
The AuthWithChangePassword application consists of one screen and a button:
authWithChangePassword. Authentication with password change.
To view application work results, use the interactive example:
Click the authWithChangePassword button.
package ru.authWithChangePassword.app2;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.mobrun.plugin.api.HyperHive;
import com.mobrun.plugin.api.HyperHiveState;
import com.mobrun.plugin.api.VersionAPI;
import com.mobrun.plugin.models.BaseStatus;
public class PasswordChangeActivity extends AppCompatActivity {
private static final String TAG = PasswordChangeActivity.class.getSimpleName();
private static final String URL = "https://testmasterfmp.fsight.cloud/";
private static final VersionAPI API_VERSION = VersionAPI.V_1;
private static final String ENVIRONMENT = "android_test";
private static final String PROJECT = "instrumented_test";
private static final String PROJECT_VERSION = "v1";
private static final String LOGIN = "android";
private static final String PASSWORD = "betterthanios";
private HyperHive hyperHive;
private Handler uiHandler;
private Button btn;
private TextView txt;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_password_change);
uiHandler = new Handler();
hyperHive = new HyperHiveState(getApplicationContext())
.setHostWithSchema(URL)
.setApiVersion(API_VERSION)
.setEnvironmentSlug(ENVIRONMENT)
.setProjectSlug(PROJECT)
.setVersionProject(PROJECT_VERSION)
.setHandler(uiHandler)
.buildHyperHive();
auth();
btn = ((Button) findViewById(R.id.activity_password_change_btn));
txt = ((TextView) findViewById(R.id.activity_password_change_txt));
btn.setOnClickListener((v) -> authWithChangePassword());
}
private void authWithChangePassword() {
Log.d(TAG, "authWithChangePassword()");
final String tmp_password = "123123";
// Replace password with temporary one
BaseStatus status_change = hyperHive.authAPI.authWithChangePassword(
LOGIN,
PASSWORD,
tmp_password,
tmp_password,
true
).execute();
// Authorize with new password
BaseStatus status_check_change = hyperHive.authAPI.auth(
LOGIN,
tmp_password,
true
).execute();
// Get old password
BaseStatus status_change_back = hyperHive.authAPI.authWithChangePassword(
LOGIN,
tmp_password,
PASSWORD,
PASSWORD,
true
).execute();
// Authorize with old password
BaseStatus status_check_change_back = hyperHive.authAPI.auth(
LOGIN,
PASSWORD,
true
).execute();
String result =
"password change: " + status_change.isOk() + '\n'
+ "normal auth: " + status_check_change.isOk() + '\n'
+ "password change back: " + status_change_back.isOk() + '\n'
+ "normal auth: " + status_check_change_back.isOk();
txt.setText(result);
Log.d(TAG, "authWithChangeStatus() result: " + result);
}
private void auth() {
Toast.makeText(this, "auth: " + hyperHive.authAPI
.auth(LOGIN, PASSWORD, true).execute().isOk(), Toast.LENGTH_LONG).show();
}
}
See. also:
Examples of Authentication on Mobile Platform Server | User Authentication by login and Password