Commit fd2102cf authored by Tanmim Hanifa's avatar Tanmim Hanifa

Added password validation

parent 902da31e
......@@ -31,11 +31,14 @@ public class RegisterActivity extends AppCompatActivity {
final Spinner gSpinner = (Spinner) findViewById(R.id.gSpinner);
final EditText etPasswordAgain = (EditText) findViewById(R.id.etPasswordAgain);
final Button btnRegister = (Button) findViewById(R.id.btnRegister);
btnRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String name = etName.getText().toString();
final String username = etUsername.getText().toString();
final String password = etPassword.getText().toString();
......@@ -44,37 +47,50 @@ public class RegisterActivity extends AppCompatActivity {
final String gender = gSpinner.getSelectedItem().toString();
Response.Listener<String> responseListener = new Response.Listener<String>(){
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
if(success){
Intent intent = new Intent(RegisterActivity.this, loginActivity.class);
RegisterActivity.this.startActivity(intent);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(RegisterActivity.this);
builder.setMessage("Username or email may already be in use.")
.setNegativeButton("Try again", null)
.create()
.show();
}
final String passwordAgain = etPasswordAgain.getText().toString();
if((password).equals(passwordAgain)) {
} catch (JSONException e) {
e.printStackTrace();
Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
if (success) {
Intent intent = new Intent(RegisterActivity.this, loginActivity.class);
RegisterActivity.this.startActivity(intent);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(RegisterActivity.this);
builder.setMessage("Username or email may already be in use.")
.setNegativeButton("Try again", null)
.create()
.show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
};
};
RegisterRequest registerRequest = new RegisterRequest(name, gender, username, dob, email, password, responseListener);
RequestQueue queue = Volley.newRequestQueue(RegisterActivity.this);
queue.add(registerRequest);
RegisterRequest registerRequest = new RegisterRequest(name, gender, username, dob, email, password, responseListener);
RequestQueue queue = Volley.newRequestQueue(RegisterActivity.this);
queue.add(registerRequest);
} else {
AlertDialog.Builder builder2 = new AlertDialog.Builder(RegisterActivity.this);
builder2.setMessage("Passwords are not the same")
.setNegativeButton("Try again", null)
.create()
.show();
}
}
});
}
}
......@@ -76,6 +76,16 @@
android:layout_marginBottom="10dp"
android:layout_below="@+id/etUsername"
android:layout_alignStart="@+id/etUsername" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/etPasswordAgain"
android:layout_marginBottom="10dp"
android:hint="Re-enter password"
android:layout_below="@id/etPassword"
android:layout_alignStart="@+id/etPassword"/>
<Button
android:text="REGISTER"
......@@ -83,7 +93,7 @@
android:layout_height="wrap_content"
android:id="@+id/btnRegister"
android:layout_marginBottom="7dp"
android:layout_below="@id/etPassword"
android:layout_below="@id/etPasswordAgain"
android:layout_centerHorizontal="true" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment