Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix#1233:Password verification before changing password added #1234

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mifospay/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
<activity
android:name=".password.ui.EditPasswordActivity"
android:theme="@style/AppTheme" />
<activity android:name=".passcode.ui.EditPasscodeActivity"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.mifos.mobilewallet.mifospay.editprofile.EditProfileContract;
import org.mifos.mobilewallet.mifospay.editprofile.presenter.EditProfilePresenter;
import org.mifos.mobilewallet.mifospay.passcode.ui.PassCodeActivity;
import org.mifos.mobilewallet.mifospay.passcode.ui.EditPasscodeActivity;
import org.mifos.mobilewallet.mifospay.password.ui.EditPasswordActivity;
import org.mifos.mobilewallet.mifospay.utils.Constants;
import org.mifos.mobilewallet.mifospay.utils.DialogBox;
Expand Down Expand Up @@ -166,13 +167,8 @@ public void onChangePasswordClicked() {

@OnClick(R.id.btn_change_passcode)
public void onChangePasscodeClicked() {
String currentPasscode = passcodePreferencesHelper.getPassCode();
// for re-initiating passcode generation process
passcodePreferencesHelper.savePassCode("");
Intent intent = new Intent(this, PassCodeActivity.class );
intent.putExtra(Constants.CURRENT_PASSCODE, currentPasscode);
intent.putExtra(Constants.UPDATE_PASSCODE, true);
startActivity(intent);
Intent i = new Intent(EditProfileActivity.this, EditPasscodeActivity.class);
startActivityForResult(i , Constants.PASSCODE_VERIFICATION);
}

@OnTextChanged({R.id.et_edit_profile_username, R.id.et_edit_profile_email,
Expand Down Expand Up @@ -312,7 +308,6 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_READ_IMAGE && data != null) {
Uri selectedImageUri = data.getData();
Expand All @@ -325,6 +320,14 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Bundle extras = data.getExtras();
Bitmap profileBitmapImage = (Bitmap) extras.get("data");
ivUserImage.setImageBitmap(profileBitmapImage);
} else if ( requestCode == Constants.PASSCODE_VERIFICATION) {
String currentPasscode = passcodePreferencesHelper.getPassCode();
// for re-initiating passcode generation process
passcodePreferencesHelper.savePassCode("");
Intent intent = new Intent(this, PassCodeActivity.class );
intent.putExtra(Constants.CURRENT_PASSCODE, currentPasscode);
intent.putExtra(Constants.UPDATE_PASSCODE, true);
startActivity(intent);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
package org.mifos.mobilewallet.mifospay.passcode.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.AppCompatButton;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.mifos.mobile.passcode.MifosPassCodeView;
import com.mifos.mobile.passcode.utils.EncryptionUtil;
import com.mifos.mobile.passcode.utils.PasscodePreferencesHelper;

import org.mifos.mobilewallet.mifospay.R;


public class EditPasscodeActivity extends AppCompatActivity implements MifosPassCodeView.
PassCodeListener {

NestedScrollView clRootview;
AppCompatButton btnForgotPasscode;
MifosPassCodeView mifosPassCodeView;
AppCompatButton btnSkip;
Button btnSave;
TextView tvPasscodeIntro;
ImageView ivVisibility;
private PasscodePreferencesHelper passcodePreferencesHelper;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pass_code);

clRootview = findViewById(R.id.cl_rootview);
btnForgotPasscode = findViewById(R.id.btn_forgot_passcode);
mifosPassCodeView = findViewById(R.id.pv_passcode);
btnSkip = findViewById(R.id.btn_skip);
btnSkip.setText(getString(R.string.cancel));
btnSave = findViewById(R.id.btn_save);
btnSave.setText(getString(R.string.ok));
tvPasscodeIntro = findViewById(R.id.tv_passcode);
tvPasscodeIntro.setText(getString(R.string.enter_passcode));
ivVisibility = findViewById(R.id.iv_visibility);
passcodePreferencesHelper = new PasscodePreferencesHelper(this);
}

private String encryptPassCode(String passCode) {
String encryptedPassCode = EncryptionUtil.getMobileBankingHash(passCode);
return encryptedPassCode;
}


public void savePassCode(View view) {
if (isPassCodeLengthCorrect()) {
if (encryptPassCode(mifosPassCodeView.getPasscode()).equals(passcodePreferencesHelper
.getPassCode())
) {
Intent resultIntent = new Intent();
setResult(Activity.RESULT_OK, resultIntent);
finish();
} else {
Toast.makeText(this, getString(R.string.incorrect_passcode),
Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(this, getString(R.string.invalid_passcode),
Toast.LENGTH_SHORT).show();
}
}

@Override
public void passCodeEntered(String passcode) { }

public void clickedOne(View v) {
mifosPassCodeView.enterCode(getString(R.string.one));
}

public void clickedTwo(View v) {
mifosPassCodeView.enterCode(getString(R.string.two));
}

public void clickedThree(View v) {
mifosPassCodeView.enterCode(getString(R.string.three));
}

public void clickedFour(View v) {
mifosPassCodeView.enterCode(getString(R.string.four));
}

public void clickedFive(View v) {
mifosPassCodeView.enterCode(getString(R.string.five));
}

public void clickedSix(View v) {
mifosPassCodeView.enterCode(getString(R.string.six));
}

public void clickedSeven(View v) {
mifosPassCodeView.enterCode(getString(R.string.seven));
}

public void clickedEight(View v) {
mifosPassCodeView.enterCode(getString(R.string.eight));
}

public void clickedNine(View v) {
mifosPassCodeView.enterCode(getString(R.string.nine));
}

public void clickedZero(View v) {
mifosPassCodeView.enterCode(getString(R.string.zero));
}

public void clickedBackSpace(View v) {
mifosPassCodeView.backSpace();
}

public void skip(View v) {
finish();
}

/**
* @param view PasscodeView that changes to text if it was hidden and vice a versa
*/
public void visibilityChange(View view) {
mifosPassCodeView.revertPassCodeVisibility();
if (!mifosPassCodeView.passcodeVisible()) {
ivVisibility.setColorFilter(
ContextCompat.getColor(EditPasscodeActivity.this,
R.color.light_grey));
} else {
ivVisibility.setColorFilter(ContextCompat.getColor(
EditPasscodeActivity.this,
R.color.gray_dark));
}
}

/**
* Checks whether passcode entered is of correct length
*
* @return Returns true if passcode lenght is 4 else shows message
*/
private boolean isPassCodeLengthCorrect() {
if (mifosPassCodeView.getPasscode().length() == 4) {
return true;
}
return false;
}

@Override
public void onBackPressed() { }

@Override
protected void onResume() {
super.onResume();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class Constants {
public static final String KYC_REGISTRATION_LEVEL_3 = "KYC Registration Level 3";
public static final String OK = "OK";
public static final String SCAN_CODE = "Scan code";
public static final int PASSCODE_VERIFICATION = 299;
public static final String QR_CODE = "QR code";
public static final String FAILED_TO_WRITE_DATA_TO_QR = "Failed to write data to qr";
public static final String ERROR_OCCURRED = "Error occurred";
Expand Down
6 changes: 4 additions & 2 deletions mifospay/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<resources>
<string name="app_name">Mifos Pay</string>

<string name="invalid_passcode">Invalid Passcode</string>
<string name="incorrect_passcode">Incorrect Passcode</string>
<string name="enter_passcode">Enter your passcode</string>
<string name="open_drawer">Open Drawer</string>
<string name="close_drawer">Close Drawer</string>
<string name="cancel_txt">Cancel</string>
Expand Down Expand Up @@ -262,7 +264,7 @@
<string name="amount">Amount</string>
<string name="merchant_history_message">The transaction history with this merchant will be shown here</string>
<string name="log_out_title">Do you want to logout?</string>
<string name="ok">Ok</string>
<string name="ok">OK</string>
<string name="alert_disable_account">Are you sure you want to disable account?</string>
<string name="alert_disable_account_desc">This will delete all the information about your account</string>
<string name="transfer_money_to_this_merchant">Transfer money to this merchant</string>
Expand Down