parent
a0ff98ae48
commit
25410c9499
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,2 +1,2 @@
|
||||
#Fri Apr 25 19:53:31 CST 2025
|
||||
java.home=/Applications/Android Studio.app/Contents/jbr/Contents/Home
|
||||
#Mon May 26 14:33:47 GMT+08:00 2025
|
||||
java.home=D\:\\Android\\AS_INstall\\jbr
|
||||
|
Binary file not shown.
@ -1 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -0,0 +1,123 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<JetCodeStyleSettings>
|
||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||
</JetCodeStyleSettings>
|
||||
<codeStyleSettings language="XML">
|
||||
<option name="FORCE_REARRANGE_MODE" value="1" />
|
||||
<indentOptions>
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||
</indentOptions>
|
||||
<arrangement>
|
||||
<rules>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:android</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:id</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:name</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>name</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>style</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>ANDROID_ATTRIBUTE_ORDER</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_ATTRIBUTE />
|
||||
<XML_NAMESPACE>.*</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
</rules>
|
||||
</arrangement>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="kotlin">
|
||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||
</codeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||
</state>
|
||||
</component>
|
@ -0,0 +1,49 @@
|
||||
package org.tensorflow.lite.examples.poseestimation.auth;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
public class DatabaseHelper extends SQLiteOpenHelper{
|
||||
|
||||
// 数据库信息
|
||||
private static final String DATABASE_NAME = "user_database";
|
||||
private static final int DATABASE_VERSION = 1;
|
||||
|
||||
// 表名和列名
|
||||
public static final String TABLE_USERS = "users";
|
||||
public static final String COLUMN_ID = "_id";
|
||||
public static final String COLUMN_USERNAME = "username";
|
||||
public static final String COLUMN_PASSWORD_HASH = "password_hash";
|
||||
public static final String COLUMN_AGE = "age";
|
||||
public static final String COLUMN_WEIGHT = "weight";
|
||||
public static final String COLUMN_GENDER = "gender";
|
||||
public static final String COLUMN_HEIGHT = "height";
|
||||
|
||||
// 创建表的SQL语句
|
||||
private static final String CREATE_TABLE_USERS =
|
||||
"CREATE TABLE " + TABLE_USERS + "("
|
||||
+ COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
|
||||
+ COLUMN_USERNAME + " TEXT UNIQUE NOT NULL,"
|
||||
+ COLUMN_PASSWORD_HASH + " TEXT NOT NULL"
|
||||
// + COLUMN_AGE + " INTEGER,"
|
||||
// + COLUMN_WEIGHT + " REAL,"
|
||||
// + COLUMN_GENDER + " TEXT,"
|
||||
// + COLUMN_HEIGHT + " REAL"
|
||||
+ ")";
|
||||
|
||||
// 构造函数
|
||||
public DatabaseHelper(Context context) {
|
||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
db.execSQL(CREATE_TABLE_USERS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
db.execSQL("DROP TABLE IF EXISTS " + TABLE_USERS);
|
||||
onCreate(db);
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package org.tensorflow.lite.examples.poseestimation.auth;
|
||||
|
||||
import java.io.Serializable;
|
||||
public class User implements Serializable{
|
||||
private long id;
|
||||
private String username;
|
||||
private String passwordHash;
|
||||
// private int age;
|
||||
// private float weight;
|
||||
// private String gender;
|
||||
// private float height;
|
||||
|
||||
// 构造函数、Getter和Setter方法
|
||||
public User() {}
|
||||
|
||||
public User(String username, String passwordHash) {
|
||||
this.username = username;
|
||||
this.passwordHash = passwordHash;
|
||||
// this.age = age;
|
||||
// this.weight = weight;
|
||||
// this.gender = gender;
|
||||
// this.height = height;
|
||||
}
|
||||
|
||||
// Getter和Setter方法
|
||||
public long getId() { return id; }
|
||||
public void setId(long id) { this.id = id; }
|
||||
|
||||
public String getUsername() { return username; }
|
||||
public void setUsername(String username) { this.username = username; }
|
||||
|
||||
public String getPasswordHash() { return passwordHash; }
|
||||
public void setPasswordHash(String passwordHash) { this.passwordHash = passwordHash; }
|
||||
|
||||
// public int getAge() { return age; }
|
||||
// public void setAge(int age) { this.age = age; }
|
||||
//
|
||||
// public float getWeight() { return weight; }
|
||||
// public void setWeight(float weight) { this.weight = weight; }
|
||||
//
|
||||
// public String getGender() { return gender; }
|
||||
// public void setGender(String gender) { this.gender = gender; }
|
||||
//
|
||||
// public float getHeight() { return height; }
|
||||
// public void setHeight(float height) { this.height = height; }
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
package org.tensorflow.lite.examples.poseestimation.auth;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import org.tensorflow.lite.examples.poseestimation.auth.User;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
public class UserDao {
|
||||
private DatabaseHelper databaseHelper;
|
||||
|
||||
public UserDao(Context context) {
|
||||
databaseHelper = new DatabaseHelper(context);
|
||||
}
|
||||
|
||||
// 添加用户
|
||||
public long addUser(User user) {
|
||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(DatabaseHelper.COLUMN_USERNAME, user.getUsername());
|
||||
values.put(DatabaseHelper.COLUMN_PASSWORD_HASH, user.getPasswordHash());
|
||||
// values.put(DatabaseHelper.COLUMN_AGE, user.getAge());
|
||||
// values.put(DatabaseHelper.COLUMN_WEIGHT, user.getWeight());
|
||||
// values.put(DatabaseHelper.COLUMN_GENDER, user.getGender());
|
||||
// values.put(DatabaseHelper.COLUMN_HEIGHT, user.getHeight());
|
||||
|
||||
long id = db.insert(DatabaseHelper.TABLE_USERS, null, values);
|
||||
db.close();
|
||||
return id;
|
||||
}
|
||||
|
||||
// 根据用户名获取用户
|
||||
public User getUserByUsername(String username) {
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
|
||||
String[] projection = {
|
||||
DatabaseHelper.COLUMN_ID,
|
||||
DatabaseHelper.COLUMN_USERNAME,
|
||||
DatabaseHelper.COLUMN_PASSWORD_HASH,
|
||||
// DatabaseHelper.COLUMN_AGE,
|
||||
// DatabaseHelper.COLUMN_WEIGHT,
|
||||
// DatabaseHelper.COLUMN_GENDER,
|
||||
// DatabaseHelper.COLUMN_HEIGHT
|
||||
};
|
||||
|
||||
String selection = DatabaseHelper.COLUMN_USERNAME + " = ?";
|
||||
String[] selectionArgs = { username };
|
||||
|
||||
Cursor cursor = db.query(
|
||||
DatabaseHelper.TABLE_USERS,
|
||||
projection,
|
||||
selection,
|
||||
selectionArgs,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
User user = null;
|
||||
if (cursor.moveToFirst()) {
|
||||
user = new User();
|
||||
user.setId(cursor.getLong(cursor.getColumnIndex(DatabaseHelper.COLUMN_ID)));
|
||||
user.setUsername(cursor.getString(cursor.getColumnIndex(DatabaseHelper.COLUMN_USERNAME)));
|
||||
user.setPasswordHash(cursor.getString(cursor.getColumnIndex(DatabaseHelper.COLUMN_PASSWORD_HASH)));
|
||||
// user.setAge(cursor.getInt(cursor.getColumnIndex(DatabaseHelper.COLUMN_AGE)));
|
||||
// user.setWeight(cursor.getFloat(cursor.getColumnIndex(DatabaseHelper.COLUMN_WEIGHT)));
|
||||
// user.setGender(cursor.getString(cursor.getColumnIndex(DatabaseHelper.COLUMN_GENDER)));
|
||||
// user.setHeight(cursor.getFloat(cursor.getColumnIndex(DatabaseHelper.COLUMN_HEIGHT)));
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
db.close();
|
||||
return user;
|
||||
}
|
||||
|
||||
// 检查用户名是否存在
|
||||
public boolean checkUsernameExists(String username) {
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
|
||||
String[] projection = { DatabaseHelper.COLUMN_USERNAME };
|
||||
String selection = DatabaseHelper.COLUMN_USERNAME + " = ?";
|
||||
String[] selectionArgs = { username };
|
||||
|
||||
Cursor cursor = db.query(
|
||||
DatabaseHelper.TABLE_USERS,
|
||||
projection,
|
||||
selection,
|
||||
selectionArgs,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
boolean exists = cursor.moveToFirst();
|
||||
cursor.close();
|
||||
db.close();
|
||||
|
||||
return exists;
|
||||
}
|
||||
|
||||
// 获取所有用户
|
||||
public List<User> getAllUsers() {
|
||||
List<User> userList = new ArrayList<>();
|
||||
String selectQuery = "SELECT * FROM " + DatabaseHelper.TABLE_USERS;
|
||||
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
Cursor cursor = db.rawQuery(selectQuery, null);
|
||||
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
User user = new User();
|
||||
user.setId(cursor.getLong(cursor.getColumnIndex(DatabaseHelper.COLUMN_ID)));
|
||||
user.setUsername(cursor.getString(cursor.getColumnIndex(DatabaseHelper.COLUMN_USERNAME)));
|
||||
user.setPasswordHash(cursor.getString(cursor.getColumnIndex(DatabaseHelper.COLUMN_PASSWORD_HASH)));
|
||||
// user.setAge(cursor.getInt(cursor.getColumnIndex(DatabaseHelper.COLUMN_AGE)));
|
||||
// user.setWeight(cursor.getFloat(cursor.getColumnIndex(DatabaseHelper.COLUMN_WEIGHT)));
|
||||
// user.setGender(cursor.getString(cursor.getColumnIndex(DatabaseHelper.COLUMN_GENDER)));
|
||||
// user.setHeight(cursor.getFloat(cursor.getColumnIndex(DatabaseHelper.COLUMN_HEIGHT)));
|
||||
|
||||
userList.add(user);
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
db.close();
|
||||
return userList;
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package org.tensorflow.lite.examples.poseestimation.utils;
|
||||
|
||||
import android.util.Base64;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
public class PasswordUtils {
|
||||
private static final String ALGORITHM = "SHA-256";
|
||||
private static final String SECRET_KEY = "YourSecretKey123"; // 实际应用中应存储在安全位置
|
||||
|
||||
// 生成密码哈希
|
||||
public static String hashPassword(String password) {
|
||||
try {
|
||||
MessageDigest digest = MessageDigest.getInstance(ALGORITHM);
|
||||
byte[] encodedHash = digest.digest(password.getBytes());
|
||||
|
||||
StringBuilder hexString = new StringBuilder(2 * encodedHash.length);
|
||||
for (byte b : encodedHash) {
|
||||
String hex = Integer.toHexString(0xff & b);
|
||||
if (hex.length() == 1) {
|
||||
hexString.append('0');
|
||||
}
|
||||
hexString.append(hex);
|
||||
}
|
||||
return hexString.toString();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// 验证密码
|
||||
public static boolean verifyPassword(String password, String hashedPassword) {
|
||||
String hashedInput = hashPassword(password);
|
||||
return hashedInput != null && hashedInput.equals(hashedPassword);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue