Forbid Duplicate Number OTP android
zakblacki opened this issue · 0 comments
zakblacki commented
In my signup page I want to forbid Users from using the same number.
This part is already done. The problem if a client use the same number starting with or without "0" at the beginning after country code it won't be considered as taken.
Example :
+213 056XXXX
+213 56XXXX
This will work on both cases and won't be considered as registered. How do I fix this ?
GetUserNumber
` confirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Snumber = number.getText().toString().trim();
if (Snumber.equals("") || !Patterns.PHONE.matcher(Snumber).matches() ) {
number.setError(getApplicationContext().getResources().getString(R.string.enter_number));
number.requestFocus();
} else {
Snumber = countryCodePicker.getSelectedCountryCode().toString() + number.getText().toString().trim();
if (new Check_internet_connection(getApplicationContext()).isNetworkAvailable()) { getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
relativeLayout.setVisibility(View.VISIBLE);
rotateLoading.start();
new VerifyNumberDuplication().execute();
} else {
}
public class VerifyNumberDuplication extends AsyncTask<String, Void, String> {
@Override
protected void onPreExecute() {
}
@Override
protected String doInBackground(String... params) {
try {
JSONObject obj = new JSONObject();
obj.put("operation", "verify");
obj.put("number", Snumber);
String str_req = JsonParser.multipartFormRequestForFindFriends(ServerURL.Url, "UTF-8", obj, null);
jp_obj = new JSONObject(str_req);
jar_array = jp_obj.getJSONArray("JsonData");
JSONObject c;
c = jar_array.getJSONObject(0);
server_response = c.getString("response");
if (server_response.equals("1")) {
server_response_text = c.getString("response-text");
}
else {
server_response_text = c.getString("response-text");
}
server_check = true;
} catch (Exception e) {
e.printStackTrace();
//server response/////////////////////////
server_check = false;
}
return null;
}
@Override
protected void onPostExecute(String s) {
rotateLoading.stop();
relativeLayout.setVisibility(View.GONE);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
if (server_check) {
if (server_response.equals("1")) {
} else {
Intent intent = new Intent(GetUserNumber.this, VerifyNumberActivity.class);
intent.putExtra("number", Snumber);
intent.putExtra("type", type);
startActivity(intent);
}
}
}}`
load_data.php
`//number verification
if($operation && $operation == 'verify' && $number)
{
$select = 'select * from users where number="'.$number.'" ';
$query = $conect->select_custom($select);
if($query->num_rows > 0)
{
$JsonArray = array();
$JsonArray[] = array('response'=>'1', 'response-text'=>'Number already used');
echo json_encode(array('JsonData'=>$JsonArray),JSON_PRETTY_PRINT);
}
else
{
$JsonArray = array();
$JsonArray[] = array('response'=>'0', 'response-text'=>"This number does not exist");
echo json_encode(array('JsonData'=>$JsonArray),JSON_PRETTY_PRINT);
}
}