2012-10-22 48 views
0

我正在开发一个android应用程序。我已经创建了登录页面,但它不安全。我想使这个应用程序安全。如何在android中创建安全的登录页面?

我的代码:

Button login; 
    EditText username, password; 
    DBAdapter db = new DBAdapter(this); 
    static String code,loginSession; 

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.login); 
    username = (EditText) findViewById(R.id.usernametxt); 
    password = (EditText) findViewById(R.id.passwordtxt); 
    db.open(); 
    db.insertTest("password1"); 
    db.insertTest("password2"); 

    db.close(); 
    // login = (ImageView) findViewById(R.id.btnLogin); 
    login = (Button) findViewById(R.id.login); 
    login.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      String uname = username.getText().toString(); 
      String pass = password.getText().toString(); 

      // ---get a title--- 
      db.open(); 


      Cursor c = db.getAllTest(); 
      if (c.moveToFirst()) { 
       do { 


        if (uname.equals(c.getString(1))) { 
         code=c.getString(1); 


        } else { 
        // Toast.makeText(getApplicationContext(), 
        // "Not Authenticated User..", 
        // Toast.LENGTH_SHORT).show(); 
        } 

       } while (c.moveToNext()); 


      } 
      String pwd=code+"123"; 



      if (uname.equals("")) { 
       Toast.makeText(getApplicationContext(), 
         "Please Enter User Name.", 
         Toast.LENGTH_SHORT).show(); 
      } 
      else if(pass.equals("")) 
      { 
       Toast.makeText(getApplicationContext(), 
         "Please Enter password.", 
         Toast.LENGTH_SHORT).show(); 
      } 

      else if(uname.equals(code) && pass.equals(pwd)) 
       { 
        Intent I=new Intent(loginPage.this, Test.class); 
        startActivity(I); 

       } 
      else if(uname!=(code)|| pass!=(pwd)) 
      { 
       Toast.makeText(getApplicationContext(), 
         "Not Authenticated User..", 
         Toast.LENGTH_SHORT).show(); 
       Intent I = new Intent(loginPage.this,loginPage.class); 
       startActivity(I); 
      } 
      db.close(); 

谁能帮助我得到一个安全登录页面,让我知道什么是安全的登录凭据需要遵循?

回答

2

如果我理解正确,您想在用户输入时隐藏密码字符。 在你的布局中把android:inputType="textPassword"改为EditText控件。

+0

我已经在我的xml文件中使用了相同的android:inputType =“textPassword” –