Initial commit

This commit is contained in:
Yo Vinchen 2023-03-16 16:30:00 +08:00
parent e0051b64e5
commit 7652ffff8a
5 changed files with 86 additions and 0 deletions

View File

@ -4,6 +4,9 @@ import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
/**
* @author YoVinchen
*/
public class MainActivity extends AppCompatActivity {
@Override

View File

@ -6,6 +6,9 @@ import android.os.Bundle;
import com.youxuegu.R;
/**
* @author YoVinchen
*/
public class RegisterActivity extends AppCompatActivity {
@Override
@ -13,4 +16,5 @@ public class RegisterActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
}
}

View File

@ -14,6 +14,9 @@ import com.youxuegu.R;
import java.util.Timer;
import java.util.TimerTask;
/**
* @author YoVinchen
*/
public class SplashActivity extends AppCompatActivity {
private TextView tv_version;

View File

@ -0,0 +1,36 @@
package com.youxuegu.utils;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* @author YoVinchen
*/
public class MD5Utils {
/**
* 创建MD5加密方法md5()
*/
public static String md5(String text) {
MessageDigest digest = null;
try {
digest = MessageDigest.getInstance("md5");
byte[] result = digest.digest(text.getBytes());
StringBuilder sb = new StringBuilder();
for (byte b : result) {
//将字节byte转换为int类型的数据
int number = b & 0xff;
//将int类型的数据转换为十六进制的字符串数据
String hex = Integer.toHexString(number);
if (hex.length() == 1) {
sb.append("0" + hex);
} else {
sb.append(hex);
}
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return "";
}
}
}

View File

@ -0,0 +1,40 @@
package com.youxuegu.utils;
import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;
/**
* @author YoVinchen
*/
public class UtilsHelper {
/**
* 判断SharedPreferences文件中是否存在要保存的用户名
*
* @param context
* @param userName
* @return
*/
public static boolean isExistUserName(Context context, String userName) {
boolean has_userName = false;
SharedPreferences sp = context.getSharedPreferences("loginInfo", Context.MODE_PRIVATE);
String spPsw = sp.getString(userName, "");
if (TextUtils.isEmpty(spPsw)) {
has_userName = true;
}
return has_userName;
}
public static void saveUserInfo(Context context, String userName, String psw) {
//将密码用MD5加密
String md5Psw = MD5Utils.md5(psw);
//获取SharedPreferences类的对象sp
SharedPreferences sp = context.getSharedPreferences("loginInfo", Context.MODE_PRIVATE);
//获取编辑器对象editor
SharedPreferences.Editor editor = sp.edit();
//将用户名和密码封装到编辑器对象editor中
editor.putString(userName, md5Psw);
//提交保存信息
editor.commit();
}
}