以XML的方式保存密码
来源:互联网 发布:上海市行知实验中学 编辑:程序博客网 时间:2024/06/08 13:35
1:布局文件:
3:LoginService(保存方法的代码):
<LinearLayout xmlns: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:orientation="vertical" tools:context=".MainActivity" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="请输入用户名" /> <EditText android:id="@+id/et_usename" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="请输入密码" /> <EditText android:inputType="textPassword" android:id="@+id/password" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" > <CheckBox android:id="@+id/cb_remenber_passward" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="记住密码" /> <Button android:layout_alignParentRight="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="login" android:text="登陆" > </Button> </RelativeLayout></LinearLayout>
2:主类的代码:
package com.example.shenchao2;import android.app.Activity;import android.content.SharedPreferences;import android.os.Bundle;import android.text.TextUtils;import android.util.Log;import android.view.View;import android.widget.CheckBox;import android.widget.EditText;import android.widget.Toast;import com.example.shenchao2.service.LoginService;public class MainActivity extends Activity {private static final String TAG = "MainActivity";private EditText ed_usename;private EditText ed_password;private CheckBox cb;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);ed_usename = (EditText) this.findViewById(R.id.et_usename);ed_password = (EditText) this.findViewById(R.id.password);cb = (CheckBox) this.findViewById(R.id.cb_remenber_passward);SharedPreferences sp = getSharedPreferences("config1", MODE_PRIVATE); String usename = sp.getString("usename", ""); ed_usename.setText("usename"); String password = sp.getString("password", ""); ed_password.setText("password");}/** * 登陆成功 * * @param vew */public void login(View vew) {String usename = ed_usename.getText().toString().trim();String password = ed_password.getText().toString().trim(); // 将其内容拿出来// 判断是否为空if (TextUtils.isEmpty(usename) || TextUtils.isEmpty(password)) {Toast.makeText(this, "不能为空", Toast.LENGTH_LONG).show();} else {// 登陆,是否保存密码if (cb.isChecked()) {// 保存用户密码Log.i(TAG, "需要保存用户密码!");// 日志文件信息LoginService.saveUseInfo(this, usename, password);Toast.makeText(this, "保存用户信息成功!", Toast.LENGTH_LONG).show();}// 登陆发送消到服务器,服务器验证是否正确if ("zhangsan".equals(usename) && "123".equals(password)) {Toast.makeText(this, "登陆成功!", Toast.LENGTH_LONG).show();} else {Toast.makeText(this, "登陆失败!", Toast.LENGTH_LONG).show();}}}}
3:LoginService(保存方法的代码):
package com.example.shenchao2.service;import android.content.Context;import android.content.SharedPreferences;import android.content.SharedPreferences.Editor;public class LoginService {public static void saveUseInfo(Context context, String usename,String password) {// 文件的名字、文件访问的模式SharedPreferences sp = context.getSharedPreferences("config1",Context.MODE_PRIVATE);// 得到一个sp的编辑器Editor editor = sp.edit();editor.putString("usename", usename);editor.putString("password", password);editor.putBoolean("shenchao", true);editor.putFloat("heshiyu",123456f);editor.commit();//提交数据}}
0 0
- 以XML的方式保存密码
- 加盐hash保存密码的正确方式
- 加盐hash保存密码的正确方式
- 加盐hash保存密码的正确方式
- 加盐hash保存密码的正确方式
- 加盐hash保存密码的正确方式
- 加盐hash保存密码的正确方式
- 加盐hash保存密码的正确方式
- 保存用户名密码的另一种方式 CREDENTIALW
- 以把你所有的密码信息保存起来
- 以对象的方式处理XML
- 使用jspsmartupload组件以时间+文件类型的方式保存文件
- 在GDAL中以BSQ的方式保存GTiff文件
- Cocos2d-x 深入解析系列 : 以XML文件方式保存用户数据
- Cocos2d-x 深入解析系列 : 以XML文件方式保存用户数据
- Cocos2d-x 深入解析系列 : 以XML文件方式保存用户数据
- C#以HTTP方式导出XML类型列,并弹出保存框
- 加盐hash保存密码的正确方式(上)
- Ubuntu下设置通过NAT方式上网(静态IP)
- gem install mysql2 失败的解决方法
- Android Studio导入Project的方法
- 帧中继实验
- 微信内部浏览器私有接口 - WeixinJSBridge介绍
- 以XML的方式保存密码
- Resin#unexpected end of file in utf8 character解决过程
- Subsets
- 简单的HTML中常用的一些特效方法
- UVA10720- Graph Construction
- 动态规划—北大POJ Charm Bracelet(01背包问题)
- 对于Mahout__"推荐算法"的初步认识(2)
- OC创建类和对象 设置器和存储器
- unix网络编程卷2的头文件unpipc.h下载和编译(转)