The super admin can only enter username and password as well as user and admin. The super admin can crude accounts, while admin can also do the same except delete. and the user can only login.
package com.example.myapplication;
import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class myDbAdapter {
myDbHelper myhelper;
public myDbAdapter(Context context) {
myhelper = new myDbHelper(context);
}
static class myDbHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "LoginSystem_db";
private static final String TABLE_NAME = "LoginSystem_tb";
private static final int DATABASE_Version = 1;
private static final String USERID = "Id";
private static final String USERNAME = "Username";
private static final String USERPASSWORD = "Password";
private static final String ACCOUNTTYPE = "User_type";
private static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME +
" (" + USERID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + USERNAME + " VARCHAR(255) UNIQUE ," + USERPASSWORD + " VARCHAR(225)," + ACCOUNTTYPE + " VARCHAR(225));";
private static final String DROP_TABLE = "DROP TABLE IF EXISTS " + TABLE_NAME;
private Context context;
public myDbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_Version);
this.context = context;
}
public void onCreate(SQLiteDatabase db) {
try {
db.execSQL(CREATE_TABLE);
} catch (Exception e) {
Message.message(context, "" + e);
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
}
public Boolean insertData(String name, String pass, String type) {
SQLiteDatabase db = myhelper.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(myDbHelper.USERNAME, name);
contentValues.put(myDbHelper.USERPASSWORD, pass);
contentValues.put(myDbHelper.ACCOUNTTYPE, type);
long dData = db.insert(myDbHelper.TABLE_NAME, null, contentValues);
if (dData == -1)
return false;
else
return true;
}
public String getData() {
SQLiteDatabase db = myhelper.getWritableDatabase();
String[] columns = {
myDbHelper.USERID,
myDbHelper.USERNAME,
myDbHelper.USERPASSWORD,
myDbHelper.ACCOUNTTYPE
};
Cursor cursor = db.query(myDbHelper.TABLE_NAME, columns, null, null, null, null, null);
StringBuffer buffer = new StringBuffer();
while (cursor.moveToNext()) {
@SuppressLint("Range") int cid = cursor.getInt(cursor.getColumnIndex(myDbHelper.USERID));
@SuppressLint("Range") String username = cursor.getString(cursor.getColumnIndex(myDbHelper.USERNAME));
@SuppressLint("Range") String password = cursor.getString(cursor.getColumnIndex(myDbHelper.USERPASSWORD));
@SuppressLint("Range") String usertype = cursor.getString(cursor.getColumnIndex(myDbHelper.ACCOUNTTYPE));
buffer.append(cid + " " + username + " " + password + " " + usertype + " \n");
}
return buffer.toString();
}
public Boolean checkusername(String username) {
SQLiteDatabase MyDB = myhelper.getWritableDatabase();
Cursor cursor = MyDB.rawQuery("Select * from LoginSystem_tb where USERNAME = ?", new String[] {
username
});
if (cursor.getCount() > 0)
return true;
else
return false;
}
public Boolean checkusernamepassword(String username, String password) {
SQLiteDatabase MyDB = myhelper.getWritableDatabase();
Cursor cursor = MyDB.rawQuery("Select * from LoginSystem_tb where USERNAME = ? and PASSWORD = ?", new String[] {
username,
password
});
if (cursor.getCount() > 0)
return true;
else
return false;
}
public Boolean checkuserType() {
SQLiteDatabase MyDB = myhelper.getWritableDatabase();
Cursor cursor = MyDB.rawQuery("Select * from LoginSystem_tb where USERTYPE= 'Admin'", new String[] {});
if (cursor.getCount() > 0)
return true;
else
return false;
}
超级管理员、管理员和用户。超级管理员可以为用户和管理员创建用户名、密码和用户类型(单选按钮)。我想做的是,当我输入登录用户名和密码时,系统将自动知道该用户是管理员或用户。如何获取已插入sql db的单选按钮的数据
}
如何获取已经存储在sql db中的用户类型(单选按钮)的数据。然后将其放入if条件。如果我的问题是正确的,但我想要的是区分用户和管理员。谢谢!输出
MainActivity.java
buttonLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String usernameLog = usernameOutside.getText().toString();
String passwordLog = passwordOutside.getText().toString();
if ((usernameLog.equals("admin")) && (passwordLog.equals("admin"))) {
Intent intent = new Intent(MainActivity.this,
MainActivity2.class);
startActivity(intent);
} else {
Boolean checkUserPass = mynewdbAdapter.checkusernamepassword(usernameLog, passwordLog);
if (checkUserPass) { //check if existing
if ( //check if this is user or admin) {
Toast.makeText(MainActivity.this, "Login Successful.", Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(MainActivity.this, "Invalid.", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(MainActivity.this, "Account doesn't exist.", Toast.LENGTH_SHORT).show();
}
}
}
});
How can I get the data which is the user type(radio button) that is already stored in the sql db. Then put it in if conditions. Idk if my questions are right but What I want is differentiate user and admin. Thank you!
输出
里面输出
我认为您需要修复getUserType()函数
你可以:
我希望这对你有帮助
从长远来看,函数可以如下所示:
public Boolean checkuserType(string input_name) {
SQLiteDatabase MyDB = myhelper.getWritableDatabase();
Cursor cursor = MyDB.rawQuery("Select USERTYPE from LoginSystem_tb where USERNAME= input_name", new String[] {});
if (cursor.fetchOne().equals("ADMIN"))
return true;
else
return false;
}
前端如何判断用户的 mac 是 arm 还是 x86 https://www.telerik.com/download/fiddler-everywhere 下载 fiddler-everywhere 的时候,它监测到了我的电脑是 arm 怎么实现的?浏览器的 UA 都还是谎称自己是 intel 是通过 js 调用浏览器 API 获得的结果吗?对应的 API 是哪个呢?
系统的日志需要登录和登出闭环,即有一个用户登录日志,就需要有一条登出日志。 如果用户通过登出按钮手动登出,触发登出接口是没问题的。 但是大多数用户,包括我自己都是直接点击x,关闭系统。 于是我监听了beforeunload事件,想在这里发登出请求。 现在遇到两个问题,一是:刷新也会触发这个事件。 二是:触发这个事件后的弹窗 重新加载是刷新弹出的,离开时关闭弹出的,我只想在点击离开的时候触发登出,重
cmf_is_user_login() 功能 判断前台用户是否登录 参数 无 返回 boolean
X1.0新增 sp_is_user_login() 功能: 判断用户是否已经登录 参数: 无 返回: 类型布尔 true/false
本文向大家介绍js如何判断用户是否是用微信浏览器,包括了js如何判断用户是否是用微信浏览器的使用技巧和注意事项,需要的朋友参考一下 上周接到个需求,需求是这样的:用户扫一扫二维码会产生一个链接,该链接会向后端发送个请求,返回一个 apk 的下载地址,用户点击下载按钮可以下载此 apk。然后就发生了问题,经过测试,发现用微信扫一扫打开的页面点击下载按钮下载不了 apk,后百度之,原来是微信内置浏览器
cmf_is_user_login() 功能 判断前台用户是否登录 参数 无 返回 boolean