首页 > 其他分享 >软工日报4.17

软工日报4.17

时间:2024-06-19 22:35:44浏览次数:10  
标签:layout 4.17 日报 ed 软工 content wrap android id

今日,我主要负责实现应用中的登录注册功能。然而,在开始编码之前,我发现了一个关键的问题——数据库中的用户表尚未建立。因此,我首先决定先创建这个用户表,以支持后续的登录注册操作。

在创建用户表时,我考虑了用户所需的基本信息,如用户名、密码(通常我们会存储密码的哈希值而非明文密码,以保障安全性)、电子邮箱(可选作为找回密码的凭证)等。此外,还可能包含其他如用户状态、创建时间等字段。

一旦用户表成功建立,我便开始着手实现登录注册功能。对于最简单的登录功能,我计划首先搭建前端界面,让用户能够输入用户名和密码。然后,在后端编写逻辑来处理这些输入,验证用户名和密码的正确性。如果验证通过,则允许用户登录系统;否则,显示相应的错误信息。

在注册功能方面,我也将采用类似的流程。首先,提供一个注册界面让用户填写必要的信息(如用户名、密码、电子邮箱等)。然后,在后端对这些信息进行验证(如检查用户名是否已被注册、密码是否符合复杂度要求等)。如果验证通过,则将用户信息保存到数据库中,并显示注册成功的消息;否则,显示相应的错误信息。

今天的主要工作就是搭建这个基础的登录注册功能框架,并确保它能够正常运行。明天,我将进一步完善这些功能,如添加密码找回、账户安全设置等选项,以提供更加完善的用户体验。

package com.hui.testend;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

import com.hui.testend.mytool.Dao;
import com.hui.testend.recongnize.baiduapi;

public class loginActivity extends AppCompatActivity implements View.OnClickListener{
EditText ed_name,ed_pass;
Button btn_login,btn_register;
Handler mainhander;
CheckBox remember_pass,remember_login;
Dao dao=new Dao();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
auto_login();
getap();
}
public void init(){
mainhander=new Handler(getMainLooper());
ed_name=findViewById(R.id.ed_name);
ed_pass=findViewById(R.id.ed_pass);
btn_login=findViewById(R.id.btn_login);
btn_register=findViewById(R.id.btn_register);
btn_login.setOnClickListener(this);
btn_register.setOnClickListener(this);
remember_pass=findViewById(R.id.cb_rember_pass);
remember_login=findViewById(R.id.cb_rember_login);
}

@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.btn_login:
login();
break;
case R.id.btn_register:
register();
break;
}
}
public void register(){
Intent intent=new Intent(loginActivity.this,register.class);
startActivity(intent);
}
public void login(){
new Thread(new Runnable() {
@Override
public void run() {
String name=ed_name.getText().toString().trim();
String password=ed_pass.getText().toString().trim();
boolean key=dao.login(name,password);
mainhander.post(new Runnable() {
@Override
public void run() {
if (key){
setap(name,password);
Toast.makeText(loginActivity.this,"登陆成功",Toast.LENGTH_SHORT).show();
Intent intent=new Intent(loginActivity.this, MainActivity.class);
startActivity(intent);
loginActivity.this.finish();
}
else {
SharedPreferences spf=getSharedPreferences("Spf",MODE_PRIVATE);
SharedPreferences.Editor edit=spf.edit();
edit.putBoolean("remember_pass",false);
Toast.makeText(loginActivity.this,"登陆失败",Toast.LENGTH_SHORT).show();
}
}
});
}
}).start();
}
public void setap(String name,String password){
SharedPreferences spf=getSharedPreferences("Spf",MODE_PRIVATE);
SharedPreferences.Editor edit=spf.edit();
edit.putString("name",name);
edit.putString("password",password);
if (remember_pass.isChecked()){
edit.putBoolean("remember_pass",true);
}
if (remember_login.isChecked()){
edit.putBoolean("remember_login",true);
}
edit.apply();
}
public void getap(){
SharedPreferences spf=getSharedPreferences("Spf",MODE_PRIVATE);
if(spf.getBoolean("remember_pass",false)){
ed_name.setText(spf.getString("name",""));
ed_pass.setText(spf.getString("password",""));
remember_pass.setChecked(true);
}

}
public void auto_login(){
SharedPreferences spf=getSharedPreferences("Spf",MODE_PRIVATE);
if (spf.getBoolean("remember_login",false)){
Intent intent=new Intent(loginActivity.this, MainActivity.class);
startActivity(intent);
}
}
} package com.hui.testend;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.hui.testend.mytool.Dao;

public class register extends AppCompatActivity implements View.OnClickListener {
EditText ed_name,ed_pass,ed_phone;
Button btn_sub_register;
Handler mainhander;
Dao dao=new Dao();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
init();
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.btn_sub_resgiter:
register();
break;
}
}
public void register(){
new Thread(new Runnable() {
@Override
public void run() {
String name=ed_name.getText().toString().trim();
String password=ed_pass.getText().toString().trim();
String phone=ed_phone.getText().toString().trim();
int a=dao.register(name,password,phone);
mainhander.post(new Runnable() {
@Override
public void run() {
if (a==1){
Toast.makeText(register.this,"注册成功",Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(register.this,"注册失败",Toast.LENGTH_SHORT).show();
}
}
});
}
}).start();
}
public void init(){
mainhander=new Handler(getMainLooper());
ed_name=findViewById(R.id.ed_name);
ed_pass=findViewById(R.id.ed_pass);
ed_phone=findViewById(R.id.ed_phone);
btn_sub_register=findViewById(R.id.btn_sub_resgiter);
btn_sub_register.setOnClickListener(this);
}
} <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="5dp"
tools:context=".register">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="注册"
android:textSize="50sp"
android:textStyle="bold"
android:textColor="@color/teal_700"
android:layout_gravity="center"
/>
<LinearLayout
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="用户名:"/>
<EditText
android:id="@+id/ed_name"
android:layout_width="match_parent"
android:layout_height="38dp"
android:background="@drawable/ed_backgroud"/>
</LinearLayout>
<LinearLayout
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密 码:"/>
<EditText
android:id="@+id/ed_pass"
android:layout_width="match_parent"
android:layout_height="38dp"
android:background="@drawable/ed_backgroud"/>
</LinearLayout>
<LinearLayout
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="电 话:"/>
<EditText
android:id="@+id/ed_phone"
android:background="@drawable/ed_backgroud"
android:layout_width="match_parent"
android:layout_height="38dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">

<TextView
android:id="@+id/tv_gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="性别"
android:textSize="20sp" />

<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">

<RadioButton
android:id="@+id/rb_boy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男" />

<RadioButton
android:id="@+id/rb_girl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="女" />
</RadioGroup>

</LinearLayout>

<Button
android:id="@+id/btn_sub_resgiter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="提交"
android:background="@drawable/btn_bg_selector"/>

</LinearLayout> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
android:padding="10dp"
android:layout_margin="10dp"
tools:context=".loginActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="主界面"
android:textSize="50sp"
android:textStyle="bold"
android:textColor="@color/teal_700"
android:layout_gravity="center"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:orientation="horizontal"
>
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="用户名:"
android:textSize="20sp"
android:paddingRight="5dp"/>
<EditText
android:id="@+id/ed_name"
android:layout_width="match_parent"
android:layout_height="38dp"
android:background="@drawable/ed_backgroud"
android:textSize="20sp"
android:textStyle="bold"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:orientation="horizontal"
>
<TextView
android:id="@+id/tv_pass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密 码:"
android:textSize="20sp"
android:paddingRight="5dp"/>
<EditText
android:id="@+id/ed_pass"
android:layout_width="match_parent"
android:layout_height="38dp"
android:inputType="numberPassword"
android:background="@drawable/ed_backgroud"
android:textSize="20sp"
android:textStyle="bold"/>
</LinearLayout>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="40dp">
<CheckBox
android:id="@+id/cb_rember_pass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="记住密码"
android:layout_marginRight="120dp"/>
<CheckBox
android:id="@+id/cb_rember_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="自动登录"/>
</RadioGroup>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="20dp">
<Button
android:id="@+id/btn_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="登录"
android:textSize="20sp"
android:textStyle="bold"
android:layout_marginRight="120dp"
android:layout_marginLeft="20dp"
android:background="@drawable/btn_bg_selector"
/>

<Button
android:id="@+id/btn_register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="注册"
android:textSize="20sp"
android:textStyle="bold"
android:background="@drawable/btn_bg_selector"/>
</LinearLayout>

</LinearLayout>  

标签:layout,4.17,日报,ed,软工,content,wrap,android,id
From: https://www.cnblogs.com/guozi6/p/18257647

相关文章

  • 软工日报3.26
    代码量:8-4【Python0036】中文级联菜单分数10全屏浏览作者 doublebest单位 石家庄铁道大学编写程序实现中文级联菜单,建议可以使用pypinyin或其它扩展库。代码:defdisplay_menu(menu,level=0):"""递归显示菜单"""forindex,(key,v......
  • 软工日报3.25
    代码量:8-3【Python0035】英文统计分数10全屏浏览作者 doublebest单位 石家庄铁道大学编写程序实现对特定英文文章(文本文件)的单词数和有效行数的统计,其中要求空行不计数;代码:importrefile="HarryPotterAndTheChamberOfSecrets.txt......
  • 软工日报3.22
    代码量:8-2【Python0032】谢宾斯基三角型字符分形图形输出分数10全屏浏览作者 doublebest单位 石家庄铁道大学要求编程输出如下图示的字符分形图形(谢宾斯基三角形),要求提交源代码文件,其中源代码要求逐行注释。 代码:importturtle......
  • 软工日报3.21
    代码量:8-1【Python0031】简易带参计算器分数10全屏浏览作者 doublebest单位 石家庄铁道大学设计一个简易的参数计算器。【输入格式】第一行输入待计算的带变量参数的计算式第二行输入各变量参数的赋值序列【输出格式】输出带变量参数的计算式的计......
  • 软工日报3.13
    代码量:7-1产生每位数字相同的n位数分数15全屏浏览切换布局作者 陈春晖单位 浙江大学读入2个正整数A和B,1<=A<=9,1<=B<=10,产生数字AA...A,一共B个A输入格式:在一行中输入A和B。输出格式:在一行中输出整数AA...A,一共B个A输入样例1:在这......
  • 软工日报3.20
    代码量:6-1使用函数输出指定范围内Fibonacci数的个数分数20全屏浏览切换布局作者 陈春晖单位 浙江大学本题要求实现一个计算Fibonacci数的简单函数,并利用其实现另一个函数,输出两正整数m和n(0<m<n≤100000)之间的所有Fibonacci数的数目。所谓Fib......
  • 软工日报3.19
    代码量:6-1使用函数求特殊a串数列和分数30全屏浏览切换布局作者 陈春晖单位 浙江大学给定两个均不超过9的正整数a和n,要求编写函数fn(a,n)求a+aa+aaa++⋯+aa⋯aa(n个a)之和,fn须返回的是数列和函数接口定义: fn(a,n)其中a和n都是用户传......
  • 软工日报3.18
    代码量:7-1jmu-python-汇率兑换分数10全屏浏览切换布局作者 蔡莉白单位 集美大学按照1美元=6人民币的汇率编写一个美元和人民币的双向兑换程序输入格式:输入人民币或美元的金额,人民币格式如:R100,美元格式如:$100输出格式:输出经过汇率计算的......
  • 软工日报3.15
    时长:五十分钟代码量:7-1图的字典表示分数20全屏浏览切换布局作者 陈春晖单位 浙江大学有向图的字典表示。输入多行字符串,每行表示一个顶点和该顶点相连的边及长度,输出顶点数,边数,边的总长度。比如上图0点表示:{'O':{'A':2,'B':5,'C':4}}。用ev......
  • 软工日报3.14
    代码量:7-1jmu-python-输入输出-计算字符串中的数分数10全屏浏览切换布局作者 郑如滨单位 集美大学将字符串中的每个数都抽取出来,然后统计所有数的个数并求和。输入格式:一行字符串,字符串中的数之间用1个空格或者多个空格分隔。输出格式:......