安卓实现密码保存和自动登录.docx

上传人:b****2 文档编号:659356 上传时间:2023-04-29 格式:DOCX 页数:19 大小:466.46KB
下载 相关 举报
安卓实现密码保存和自动登录.docx_第1页
第1页 / 共19页
安卓实现密码保存和自动登录.docx_第2页
第2页 / 共19页
安卓实现密码保存和自动登录.docx_第3页
第3页 / 共19页
安卓实现密码保存和自动登录.docx_第4页
第4页 / 共19页
安卓实现密码保存和自动登录.docx_第5页
第5页 / 共19页
安卓实现密码保存和自动登录.docx_第6页
第6页 / 共19页
安卓实现密码保存和自动登录.docx_第7页
第7页 / 共19页
安卓实现密码保存和自动登录.docx_第8页
第8页 / 共19页
安卓实现密码保存和自动登录.docx_第9页
第9页 / 共19页
安卓实现密码保存和自动登录.docx_第10页
第10页 / 共19页
安卓实现密码保存和自动登录.docx_第11页
第11页 / 共19页
安卓实现密码保存和自动登录.docx_第12页
第12页 / 共19页
安卓实现密码保存和自动登录.docx_第13页
第13页 / 共19页
安卓实现密码保存和自动登录.docx_第14页
第14页 / 共19页
安卓实现密码保存和自动登录.docx_第15页
第15页 / 共19页
安卓实现密码保存和自动登录.docx_第16页
第16页 / 共19页
安卓实现密码保存和自动登录.docx_第17页
第17页 / 共19页
安卓实现密码保存和自动登录.docx_第18页
第18页 / 共19页
安卓实现密码保存和自动登录.docx_第19页
第19页 / 共19页
亲,该文档总共19页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

安卓实现密码保存和自动登录.docx

《安卓实现密码保存和自动登录.docx》由会员分享,可在线阅读,更多相关《安卓实现密码保存和自动登录.docx(19页珍藏版)》请在冰点文库上搜索。

安卓实现密码保存和自动登录.docx

安卓实现密码保存和自动登录

xmlversion="1.0"encoding="utf-8"?

>

android="

  android:

layout_width="fill_parent"

  android:

layout_height="fill_parent"

  android:

background="@drawable/logo_bg"

  android:

orientation="vertical">

  

    android:

layout_width="fill_parent"

    android:

layout_height="wrap_content">

    

      android:

id="@+id/img_btn"

      android:

layout_width="wrap_content"

      android:

layout_height="wrap_content"

      android:

layout_alignParentRight="true"

      android:

background="@drawable/quit"/>

    

      android:

id="@+id/tv_zh"

      android:

layout_width="wrap_content"

      android:

layout_height="35dip"

      android:

layout_marginLeft="12dip"

      android:

layout_marginTop="10dip"

      android:

gravity="bottom"

      android:

text="帐号:

"

      android:

textColor="#000000"

      android:

textSize="18sp"/>

    

      android:

id="@+id/et_zh"

      android:

layout_width="fill_parent"

      android:

layout_height="40dip"

      android:

layout_below="@id/tv_zh"

      android:

layout_marginLeft="12dip"

      android:

layout_marginRight="10dip"/>

    

      android:

id="@+id/tv_mima"

      android:

layout_width="wrap_content"

      android:

layout_height="35dip"

      android:

layout_below="@id/et_zh"

      android:

layout_marginLeft="12dip"

      android:

layout_marginTop="10dip"

      android:

gravity="bottom"

      android:

text="密码:

"

      android:

textColor="#000000"

      android:

textSize="18sp"/>

    

      android:

id="@+id/et_mima"

      android:

layout_width="fill_parent"

      android:

layout_height="40dip"

      android:

layout_below="@id/tv_mima"

      android:

layout_marginLeft="12dip"

      android:

layout_marginRight="10dip"

      android:

maxLines="200"

      android:

password="true"

      android:

scrollHorizontally="true"/>

    

      android:

id="@+id/cb_mima"

      android:

layout_width="wrap_content"

      android:

layout_height="wrap_content"

      android:

layout_below="@id/et_mima"

      android:

layout_marginLeft="12dip"

      android:

text="记住密码"

      android:

textColor="#000000"/>

    

      android:

id="@+id/cb_auto"

      android:

layout_width="wrap_content"

      android:

layout_height="wrap_content"

      android:

layout_below="@id/cb_mima"

      android:

layout_marginLeft="12dip"

      android:

text="自动登录"

      android:

textColor="#000000"/>

    

      android:

id="@+id/btn_login"

      android:

layout_width="80dip"

      android:

layout_height="40dip"

      android:

layout_below="@id/et_mima"

      android:

layout_alignParentRight="true"

      android:

layout_alignTop="@id/cb_auto"

      android:

layout_marginRight="10dip"

      android:

gravity="center"

      android:

text="登录"

      android:

textColor="#000000"

      android:

textSize="18sp"/>

     

  

   

   

布局文件:

logo.xml

xmlversion="1.0"encoding="utf-8"?

>

android="

  android:

layout_width="fill_parent"

  android:

layout_height="fill_parent"

  android:

background="@drawable/logo_bg"

  android:

orientation="vertical">

  

    android:

layout_width="fill_parent"

    android:

layout_height="wrap_content" 

    android:

layout_weight="3">

    

      android:

id="@+id/pgBar"

      android:

layout_width="wrap_content"

      android:

layout_height="wrap_content"

      android:

layout_centerInParent="true"/>

    

      android:

id="@+id/tv1"

      android:

layout_width="wrap_content"

      android:

layout_height="wrap_content"

      android:

layout_below="@id/pgBar"

      android:

layout_centerHorizontal="true"

      android:

text="正在登录..."

      android:

textColor="#000000"

      android:

textSize="18sp"/>

  

  

    android:

layout_width="fill_parent"

    android:

layout_height="wrap_content"

    android:

layout_weight="1"

    android:

gravity="center"

    android:

orientation="vertical">

    

      android:

id="@+id/btn_back"

      android:

layout_width="70dip"

      android:

layout_height="35dip"

      android:

text="取消"

      android:

textColor="#000000"

      android:

textSize="12sp"/>

  

布局文件:

welcom.xml

xmlversion="1.0"encoding="utf-8"?

>

android="

  android:

layout_width="fill_parent"

  android:

layout_height="fill_parent"

  android:

layout_gravity="center"

  android:

background="@drawable/login_bg"

  android:

orientation="vertical">

  

    android:

layout_width="fill_parent"

    android:

layout_height="wrap_content"

    android:

gravity="center"

    android:

text="登陆成功,进入用户界面"

    android:

textColor="#000000"

    android:

textSize="20sp"/>

java代码:

LoginActivity.java

packagecom.wang.activity;

importandroid.app.Activity;

importandroid.content.Context;

importandroid.content.Intent;

importandroid.content.SharedPreferences;

importandroid.content.SharedPreferences.Editor;

importandroid.os.Bundle;

importandroid.view.View;

importandroid.view.View.OnClickListener;

importandroid.view.Window;

importandroid.widget.Button;

importandroid.widget.CheckBox;

importandroid.widget.CompoundButton;

importandroid.widget.CompoundButton.OnCheckedChangeListener;

importandroid.widget.EditText;

importandroid.widget.ImageButton;

importandroid.widget.Toast;

publicclassLoginActivityextendsActivity{

privateEditTextuserName,passWord;

privateCheckBoxrem_pw,auto_login;

privateButtonbtn_login;

privateImageButtonbtnQuit;

  privateStringuserNameValue,passwordValue;

privateSharedPreferencessp;

  privatefinalStringMAK="innoview";

  publicvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

//去掉TitleBar

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

setContentView(R.layout.login);

   //获取shareprefrence里面的数据

sp=this.getSharedPreferences("userInfo",Context.MODE_WORLD_READABLE);

userName=(EditText)findViewById(R.id.et_zh);

passWord=(EditText)findViewById(R.id.et_mima);

    rem_pw=(CheckBox)findViewById(R.id.cb_mima);

auto_login=(CheckBox)findViewById(R.id.cb_auto);

    btn_login=(Button)findViewById(R.id.btn_login);

    btnQuit=(ImageButton)findViewById(R.id.img_btn);

     //判断记住密码框状态

   if(sp.getBoolean("ISCHECK",false))

    {

      //记住密码框状态标记为选中

     rem_pw.setChecked(true);

      try{

        userNameValue=sp.getString("USER_NAME","");

        System.out.println("<<<<<<<<<<<<"+"加密后的用户名"+userNameValue);

        Stringusername=AESEncryptor.decrypt(MAK,userNameValue);

        System.out.println("<<<<<<<<<<<<"+"解密后的用户名"+username);

        userName.setText(username);

      }catch(Exceptione){

        Toast.makeText(LoginActivity.this,"用户名解密异常",Toast.LENGTH_SHORT).show();

        e.printStackTrace(); //TochangebodyofcatchstatementuseFile|Settings|FileTemplates.

      }

      Stringpassword=null;

      try{

        passwordValue=sp.getString("PASSWORD","");

        System.out.println("<<<<<<<<<<<<"+"加密后的密码"+passwordValue);

        password=AESEncryptor.decrypt(MAK,passwordValue);

        System.out.println("<<<<<<<<<<<<"+"解密后的密码"+password);

      }catch(Exceptione){

        Toast.makeText(LoginActivity.this,"密码解密异常",Toast.LENGTH_SHORT).show();

        e.printStackTrace(); //TochangebodyofcatchstatementuseFile|Settings|FileTemplates.

      }

      passWord.setText(password);

      //判断自动登录框状态

     if(sp.getBoolean("AUTO_ISCHECK",false))

     {

      //自动登录框状态标记为选中

      auto_login.setChecked(true);

       

   Intentintent=newIntent(LoginActivity.this,LogoActivity.class);

  LoginActivity.this.startActivity(intent);

     }

    }

  //用户名:

login秘密:

123456

btn_login.setOnClickListener(newOnClickListener(){

publicvoidonClick(Viewv){

userNameValue=userName.getText().toString();

  passwordValue=passWord.getText().toString();

  

if(userNameValue.equals("login")&&passwordValue.equals("123456"))

{

Toast.makeText(LoginActivity.this,"登陆成功",Toast.LENGTH_SHORT).show();

//如果记住密码框未选中状态

if(rem_pw.isChecked())

{

 

 Editoreditor=sp.edit();

//            AESEncryptor.encrypt(userNameValue);

            try{

              editor.putString("USER_NAME",AESEncryptor.encrypt(MAK,userNameValue));

              System.out.println("<<<<<<<<"+"加密后的用户名"+AESEncryptor.encrypt(MAK,userNameValue));

            }catch(Exceptione){

               Toast.makeText(LoginActivity.this,"用户名加密异常",Toast.LENGTH_SHORT).show();

              e.printStackTrace(); //TochangebodyofcatchstatementuseFile|Settings|FileTemplates.

            }

            try{

              editor.putString("PASSWORD",AESEncryptor.encrypt(MAK,passwordValue));

    

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 法律文书 > 调解书

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2