0 Replies - 197 Views - Last Post: 19 June 2013 - 08:44 AM

#1 RUAg4mer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 30-July 11

Does the username already exist?

Posted 19 June 2013 - 08:44 AM

Hello All. I'm developing an App that requires a username and account password to log in. I have the log in and create account processes working.. however I'm having trouble with recognizing whether or not usernames already exist. But not all user names. The app is recognizing some of the user names I've tested with. For example usernames: a, abc, abcdefghij, test, etc. are recognized. But newer usernames I test with aren't being recognized as already existing. So I'm wondering if I've possibly filled up my database or something. (Which I don't think I have because I can still log in with newly created accounts, but they aren't recognized as already existing if I use that username again). Or maybe there is something wrong with the code. Any help would be appreciated. I'll drop in code and if you need to see more just let me know and I'll drop more in.

Code section from Create Account Screen (.java)
            String userName=createUserNameText.getText().toString();
            String password=createPasswordText.getText().toString();
            String confirmPassword=createPasswordConfirmText.getText().toString();
            String takenUserName= loginDataBaseAdapter.getSingleEntry(userName);
            
            if(userName.equals(takenUserName))   
            {
            	Toast.makeText(getApplicationContext(), "UserName Already Taken", Toast.LENGTH_LONG).show();
            	return;
            }
            
            // check if any of the fields are vacant
            if(userName.equals("")||password.equals("")||confirmPassword.equals(""))
            {
                Toast.makeText(getApplicationContext(), "Field Vaccant", Toast.LENGTH_LONG).show();
                return;
            }
            // check if both password matches
            if(!password.equals(confirmPassword))
            {
                Toast.makeText(getApplicationContext(), "Password does not match", Toast.LENGTH_LONG).show();
                return;
            }
            else
            {
                // Save the Data in Database
                loginDataBaseAdapter.insertEntry(userName, password);
                Toast.makeText(getApplicationContext(), "Account Successfully Created ", Toast.LENGTH_LONG).show();



Account Screen
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/question_mark_background"
    android:orientation="vertical" >
    
    <EditText
        android:id="@+id/createAccountScreenInputUserName"
        android:hint="User Name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
 
        <requestFocus />
    </EditText>
 
    <EditText
        android:id="@+id/createAccountScreenInputPassword"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
         android:hint="Password"
        android:inputType="textPassword" />
 
    <EditText
        android:id="@+id/createAccountScreenInputConfirmPassword"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Confirm Password"
        android:inputType="textPassword" />
 
    <Button
        android:id="@+id/createAccountScreenCreateAccountButton"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Create Account"
        android:layout_marginBottom="50dp" />
 

</LinearLayout>




Code Section from Data Base Adapter (.java)
                public void insertEntry(String userName,String password)
	        {
	        	
	           ContentValues newValues = new ContentValues();
	            // Assign values for each row.
	            newValues.put("USERNAME", userName);
	            newValues.put("PASSWORD",password);
	            
	            // Insert the row into your table
	            db.insert("LOGIN", null, newValues);
	            ///Toast.makeText(context, "Reminder Is Successfully Saved", Toast.LENGTH_LONG).show();
	        }
	        public int deleteEntry(String UserName)
	        {
	            //String id=String.valueOf(ID);
	            String where="USERNAME=?";
	            int numberOFEntriesDeleted= db.delete("LOGIN", where, new String[]{UserName}) ;
	           // Toast.makeText(context, "Number for Entry Deleted Successfully : "+numberOFEntriesDeleted, Toast.LENGTH_LONG).show();
	            return numberOFEntriesDeleted;
	        }    
	        public String getSingleEntry(String userName)
	        {
	            Cursor cursor=db.query("LOGIN", null, " USERNAME=?", new String[]{userName}, null, null, null);
	            if(cursor.getCount()<1) // UserName Not Exist
	            {
	                cursor.close();
	                return "NOT EXIST";
	            }
	            cursor.moveToFirst();
	            String password= cursor.getString(cursor.getColumnIndex("PASSWORD"));
	            cursor.close();
	            return password;                
	        }
	        public void  updateEntry(String userName,String password)
	        {
	            // Define the updated row content.
	            ContentValues updatedValues = new ContentValues();
	            // Assign values for each row.
	            updatedValues.put("USERNAME", userName);
	            updatedValues.put("PASSWORD",password);
	 
	            String where="USERNAME = ?";
	            db.update("LOGIN",updatedValues, where, new String[]{userName});               
	        }        

}




Is This A Good Question/Topic? 0
  • +

Page 1 of 1