android获取用户名和密码
❶ 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、网络存储
*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发送网络请求,还要考虑网络请求超时的情况。希望能帮到你。