當前位置:首頁 » 安卓系統 » android獲取用戶名和密碼

android獲取用戶名和密碼

發布時間: 2023-06-07 20:56:52

❶ android作業創建用戶登陸和密碼

布局文件:

<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="#efefef"

tools:context="cn.teachcourse.activity.MainActivity">


<LinearLayout

android:layout_width="match_parent"

android:layout_height="50dp"

android:layout_alignParentTop="true"

android:background="#2088c2"

android:orientation="horizontal"

android:gravity="center_horizontal">


<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginBottom="8dp"

android:layout_marginTop="8dp"

android:gravity="center_vertical"

android:text="登錄界面"

android:textSize="22sp"

android:layout_gravity="center_vertical"

android:textColor="#FFFFFF"/>

</LinearLayout>

<!--輸入用戶名框-->


<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_above="@+id/center_point"

android:background="#FFFFFF"

android:orientation="horizontal">


<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="10dp"

android:layout_marginRight="10dp"

android:drawableLeft="@drawable/user_login_icon"/>


<EditText

android:id="@+id/user_name_ET"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_gravity="center_vertical"

android:hint="@string/username_hint"/>

</LinearLayout>

<!--輸入密碼框-->


<LinearLayout

android:id="@+id/pass_word_ll"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_below="@+id/center_point"

android:background="#FFFFFF"

android:orientation="horizontal">


<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="10dp"

android:layout_marginRight="10dp"

android:drawableLeft="@drawable/user_login_lock"/>


<EditText

android:id="@+id/pass_word_ET"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_gravity="center_vertical"

android:hint="@string/password_hint"

android:inputType="textPassword"/>

</LinearLayout>


<Button

android:id="@+id/login_btn"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_below="@+id/pass_word_ll"

android:layout_margin="10dp"

android:background="@drawable/blue_bg"

android:text="@string/login_str"

android:textColor="#FFFFFF"/>


<View

android:id="@+id/center_point"

android:layout_width="1dp"

android:layout_height="1dp"

android:layout_centerInParent="true"/>


</RelativeLayout>


實現代碼:

packagecn.teachcourse.activity;


importjava.util.regex.Matcher;

importjava.util.regex.Pattern;


importcn.teachcourse.common.BaseActivity;

importcn.teachcourse.utils.SharedPreferenceUtil;


importandroid.app.Activity;

importandroid.content.Intent;

importandroid.os.Bundle;

importandroid.text.TextUtils;

importandroid.view.View;

importandroid.view.View.OnClickListener;

importandroid.widget.Button;

importandroid.widget.EditText;

importandroid.widget.Toast;


/**

*@authorTeachCourse博客保存數據的的方法有:

*1、網路存儲

*2、資料庫sqlite存儲

*3、SharedPreferences本地化存儲

*4、File文件存儲

*四種存儲數據的方法,對應的Demo:

*NetworkDemo、SQLiteDemo、SharedPreferencesDemo和FileDemo

*

*/

{

privateEditTextmUserName_ET,mPassword_ET;

privateButtonmLogin_btn;


privateStringusername;

privateStringpassword;


@Override

protectedvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

//activity_main編輯一個注冊登錄界面

setContentView(R.layout.activity_main);

SharedPreferenceUtil.initPreference(this);

initView();

}


@Override

protectedvoidonResume(){

//檢查SharedPreferences文件中是否保存有用戶名和密碼

super.onResume();

StringusernameStr=SharedPreferenceUtil.getString("username",null);

StringpasswordStr=SharedPreferenceUtil.getString("password",null);

if(!TextUtils.isEmpty(usernameStr)){

mUserName_ET.setText(usernameStr);

}elseif(!TextUtils.isEmpty(passwordStr)){


mPassword_ET.setText(passwordStr);


}


}


privatevoidinitView(){

mLogin_btn=(Button)findViewById(R.id.login_btn);

mUserName_ET=(EditText)findViewById(R.id.user_name_ET);

mPassword_ET=(EditText)findViewById(R.id.pass_word_ET);


mLogin_btn.setOnClickListener(this);

}


@Override

publicvoidonClick(Viewv){

switch(v.getId()){

caseR.id.login_btn:

login();

break;


}

}


privatevoidlogin(){

username=mUserName_ET.getText().toString().trim();

password=mPassword_ET.getText().toString().trim();

//這里只驗證格式是否合法,不驗證用戶名和密碼的正確性,SharedPreferences將數據存儲到本地

if(checkPhone(username)&&checkNotNull(password)){

SharedPreferenceUtil.putString("username",username);

SharedPreferenceUtil.putString("password",password);

toSecondActivity();

}


}


privatevoidtoSecondActivity(){

Intentintent=newIntent(this,SecondActivity.class);

Bundlebundle=newBundle();

bundle.putString("username",username);

bundle.putString("password",password);

intent.putExtras(bundle);

startActivity(intent);

MainActivity.this.finish();

}


/**

*@paramvalue需要驗證的用戶名

*@return

*/

privatebooleancheckNotNull(Stringvalue){

if(!TextUtils.isEmpty(value)){

if(value.length()<6){

Toast.makeText(this,"密碼填寫不合法!",Toast.LENGTH_LONG).show();//號碼填寫不正確

returnfalse;

}else{

returntrue;

}


}else{

Toast.makeText(this,"密碼不能為空",Toast.LENGTH_LONG).show();

returnfalse;

}

}


/**

*@paramphone需要驗證的手機號碼

*@return

*/

privatebooleancheckPhone(Stringphone){

if(!TextUtils.isEmpty(phone)){

if(ismobileNO(phone)){

returntrue;

}else{

Toast.makeText(this,"號碼填寫不正確",Toast.LENGTH_LONG).show();//號碼填寫不正確

returnfalse;

}

}else{

Toast.makeText(this,"號碼不能為空",Toast.LENGTH_LONG).show();//不能為空

returnfalse;

}

}


/**

*手機號碼的驗證,嚴格驗證

*

*@param/mobiles要驗證的手機號碼

*@return

*/

publicstaticbooleanismobileNO(Stringmobiles){

if(TextUtils.isEmpty(mobiles)){

returnfalse;

}

Patternp=Pattern

.compile("^((13[0-9])|(14[5,7])|(15[^4,\D])|(17[0,6,7,8])|(18[0-9]))\d{8}$");

Matcherm=p.matcher(mobiles);

returnm.matches();

}

}


效果圖:

安卓軟體如何提取已記住的用戶名和密碼

這類軟體目前還是很缺乏的呢,你在應用寶裡面搜索一下提取密碼軟體!
因為應用寶上面的軟體都是最齊全的,只要存在的話,就可以找到的呢!
它上面的軟體版本是正式版本,兼容很好,木有啥問題,完美運行。
和手機完美融合,經過很多手機檢測的,安全放心下載呢
在手機上打開應用寶軟體搜索你所需要的軟體或者游戲,找到下載就可以安裝了。
也可以通過手機連接電腦端的應用寶軟體來下載的,打開PC端的應用寶軟體——手機應用。
可以通過搜索或者看軟體或許游戲的分類來進行下載呢,都是很方便的。還望採納

❸ android怎樣將得到的注冊信息(賬號和密碼)寫入到一個二維數組

代碼如下
importandroid.os.Bundle;
importandroid.app.Activity;
importandroid.content.SharedPreferences;
importandroid.content.SharedPreferences.Editor;
importandroid.text.TextUtils;
importandroid.view.Menu;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.Button;
importandroid.widget.CheckBox;
importandroid.widget.EditText;
importandroid.widget.Toast;


/***
*
*1.創建一個SharedPreferences
*2.初始化SharedPreferences參數1sp的文件名稱參數2sp的保存模式
*3.向sp裡面保存數據首先獲取一個文本編輯器Editor
*4.存儲完畢數據記得執行commint()保存數據
*5.讀取數據sp.getString()sp.getInt();
*/


{
privateEditTextet_qq;
privateEditTextet_password;
privateCheckBoxcb_remeber_pwd;
privateButtonbt_ok;
/**
*android系統下用於數據存儲的一個方便的API
*/
privateSharedPreferencessp;

@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//完成sp的初始化。
sp=getSharedPreferences("config",MODE_PRIVATE);
et_qq=(EditText)findViewById(R.id.et_qq);
et_password=(EditText)findViewById(R.id.et_password);
cb_remeber_pwd=(CheckBox)findViewById(R.id.cb_remeber_pwd);

//獲取sp裡面存儲的數據
StringsavedQQ=sp.getString("qq","");
StringsavedPassword=sp.getString("password","");
et_qq.setText(savedQQ);
et_password.setText(savedPassword);

bt_ok=(Button)findViewById(R.id.bt_ok);
//給按鈕注冊一個點擊事件。
bt_ok.setOnClickListener(newOnClickListener(){

@Override
publicvoidonClick(Viewv){
Stringqq=et_qq.getText().toString();
Stringpassword=et_password.getText().toString();
if(TextUtils.isEmpty(qq)||TextUtils.isEmpty(password)){
Toast.makeText(getApplicationContext(),
"對不起,qq號"+"或者密碼不能為空",0).show();
}else{
//檢查用戶是否勾選了記住密碼的選項。
if(cb_remeber_pwd.isChecked()){
//說明勾選框被選中了。把用戶名和密碼給記錄下來
//獲取到一個參數文件的編輯器。
Editoreditor=sp.edit();
editor.putString("qq",qq);
editor.putString("password",MD5utils.encode(password));
//把數據給保存到sp裡面
editor.commit();
Toast.makeText(getApplicationContext(),"用戶信息已經保存",1)
.show();
}
}
}
});
}

}
packagecom.itheima.qqlogin;

importjava.security.MessageDigest;
importjava.security.NoSuchAlgorithmException;

importandroid.os.Message;

publicclassMD5utils{
/**
*md5加密的工具類
*
*@parampassword
*@return
*/
publicstaticStringencode(Stringpassword){
try{
MessageDigestdigest=MessageDigest.getInstance("md5");
byte[]results=digest.digest(password.getBytes());
StringBuildersb=newStringBuilder();
for(byteb:results){
intnumber=b&0xff;
Stringhex=Integer.toHexString(number);
if(hex.length()==1){
sb.append("0");
}
sb.append(hex);
}
returnsb.toString();
}catch(Exceptione){
e.printStackTrace();
return"";
}
}
}

❹ android登陸驗證是在哪裡(客戶端activity還是伺服器servlet)登陸驗證的流程是怎麼樣的

Activity通過EditText獲取用戶輸入的用戶名和密碼,先進行初步判斷,看是否符合標准(比如用戶名、密碼的長度,及包含漢字等),如果不通過彈出提示,通輪頃過的話要先判斷網路連接狀況。有網路連接時可以以http或者socket方式與伺服器通信。如果是http的優先使用post方式,這樣不會把用戶信息暴露在罩桐基url中。servlet接收到用戶名和密碼後,經過資料庫查詢,判斷各種情況,例如用戶名不存在,密碼不正確等情況,並把結果返回給Activity。具體的數據格式協議你自己訂了。Activity根據返回的結果,按照項目需求進行相應的提示或者操作即可。另外4.0以後網路請求不能在物謹Activity的ui線程中進行,需要用Thread發送網路請求,還要考慮網路請求超時的情況。希望能幫到你。

熱點內容
折紙手工解壓小方塊 發布:2025-02-08 16:32:45 瀏覽:252
php與運算符 發布:2025-02-08 16:32:45 瀏覽:762
如何用伺服器搭建懸賞平台 發布:2025-02-08 16:29:53 瀏覽:278
ftp伺服器破解版 發布:2025-02-08 16:28:41 瀏覽:521
mysql配置訪問ip 發布:2025-02-08 16:22:49 瀏覽:116
體表面積簡易演算法 發布:2025-02-08 16:18:04 瀏覽:687
存儲器的分級儲存是如何實現的 發布:2025-02-08 16:11:27 瀏覽:193
電腦怎麼看路由器密碼 發布:2025-02-08 16:10:13 瀏覽:401
匯編宏編譯 發布:2025-02-08 16:08:30 瀏覽:194
androidlayoutview 發布:2025-02-08 15:45:01 瀏覽:622