实现效果:
主要功能
注册界面含有用户名和密码,确定密码三个输入框,输入相应的内容,点击注册按钮,系统获取输入框里面的内容,判断输入的密码与再次输入的密码是不一致,与三个输入框的内容不能为空,若出现输入错误会适当进行提醒。根据账号查询数据库里面的相关内容,如果没有找到与输入账号相关的内容,对输入的密码进行加密存储,并提示“注册成功”,如果找到则比对输入的密码与数据库中保存的相关密码,则提示可以直接登陆。
xml代码
main_title_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/title_bar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@android:color/transparent">
<TextView
android:id="@+id/tv_main_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="@color/colorPrimary"
android:textSize="16sp"/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginTop="10dp"
android:padding="5dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/rand_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@drawable/book"
android:padding="2dp"
android:layout_margin="4dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="8dp"
android:layout_weight="0.6"
android:weightSum="1"
android:orientation="horizontal">
<TextView
android:id="@+id/item_note_title"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:textSize="20dp"
android:textColor="@color/colorPrimary"
android:gravity="center_vertical"
android:singleLine="true"/>
<TextView
android:id="@+id/item_note_date"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:textSize="14dp"
android:layout_gravity="right"
android:gravity="center_vertical"
android:singleLine="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="8dp"
android:layout_weight="0.4"
android:weightSum="1"
android:orientation="horizontal">
<TextView
android:id="@+id/des"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.50"
android:textSize="14dp"
android:textColor="@color/colorPrimary"
android:gravity="center_vertical"
android:singleLine="true"/>
<TextView
android:id="@+id/pre"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:textSize="14dp"
android:textColor="@color/colorPrimary"
android:layout_gravity="right"
android:gravity="center_vertical"
android:singleLine="true"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
对输入的密码进行加密处理的程序
MD5Utils.java
package com.example.lsl.daily_note;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* Created by lsl on 2020/6/7.
*/
public class MD5Utils {
//md5 加密算法
public static String md5(String text) {
MessageDigest digest = null;
try {
digest = MessageDigest.getInstance("md5");
// 数组 byte[] result -> digest.digest( ); 文本 text.getBytes();
byte[] result = digest.digest(text.getBytes());
//创建StringBuilder对象 然后建议StringBuffer,安全性高
//StringBuilder sb = new StringBuilder();
StringBuffer sb = new StringBuffer();
// result数组,digest.digest ( ); -> text.getBytes();
// for 循环数组byte[] result;
for (byte b : result){
// 0xff 为16进制
int number = b & 0xff;
// number值 转换 字符串 Integer.toHexString( );
String hex = Integer.toHexString(number);
if (hex.length() == 1){
sb.append("0"+hex);
}else {
sb.append(hex);
}
}
//sb StringBuffer sb = new StringBuffer();对象实例化
return sb.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
//发送异常return空字符串
return "";
}
}
}
注册页面的代码:
RegisterActivity.java
package com.example.lsl.daily_note;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* Created by lsl on 2020/6/7.
*/
public class MD5Utils {
//md5 加密算法
public static String md5(String text) {
MessageDigest digest = null;
try {
digest = MessageDigest.getInstance("md5");
// 数组 byte[] result -> digest.digest( ); 文本 text.getBytes();
byte[] result = digest.digest(text.getBytes());
//创建StringBuilder对象 然后建议StringBuffer,安全性高
//StringBuilder sb = new StringBuilder();
StringBuffer sb = new StringBuffer();
// result数组,digest.digest ( ); -> text.getBytes();
// for 循环数组byte[] result;
for (byte b : result){
// 0xff 为16进制
int number = b & 0xff;
// number值 转换 字符串 Integer.toHexString( );
String hex = Integer.toHexString(number);
if (hex.length() == 1){
sb.append("0"+hex);
}else {
sb.append(hex);
}
}
//sb StringBuffer sb = new StringBuffer();对象实例化
return sb.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
//发送异常return空字符串
return "";
}
}
}