密码部分功能

pull/9/head
Ryuki 2 years ago
parent 2ae54b9a3c
commit 77a0074490

@ -0,0 +1,78 @@
package net.micode.notes.ui;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import net.micode.notes.R;
public class Changepassword extends Activity{
EditText OldPassword;
EditText NewPassword;
EditText AckPassword;
Button Acknowledged;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_change_password);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
| WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
OldPassword=(EditText) findViewById(R.id.old_password);
NewPassword=(EditText) findViewById(R.id.new_password);
AckPassword=(EditText) findViewById(R.id.ack_password);
Acknowledged=(Button)findViewById(R.id.Acknowledged);
Acknowledged.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String old_password = OldPassword.getText().toString();
String new_password = NewPassword.getText().toString();
String ack_password = AckPassword.getText().toString();
SharedPreferences pref = getSharedPreferences("user
management",MODE_PRIVATE);
String login_password = pref.getString("password","");
if(old_password.equals("")==true || new_password.equals("")==true
|| ack_password.equals("")==true) {
Toast.makeText(ChangingPassword.this, "密码不能为空",
Toast.LENGTH_SHORT).show();
}
else if (new_password.equals(ack_password) == false) {
Toast.makeText(ChangingPassword.this, "
", Toast.LENGTH_SHORT).show();
AckPassword.setText("");
}
else if(old_password.equals(login_password) == false){
Toast.makeText(ChangingPassword.this, "
", Toast.LENGTH_SHORT).show();
OldPassword.setText("");
}
else if (new_password.equals(ack_password) == true &&
old_password.equals(login_password) == true){
SharedPreferences.Editor editor=getSharedPreferences("user
management", MODE_PRIVATE).edit();
editor.putString("password",new_password);
editor.apply();
Toast.makeText(ChangingPassword.this, "修改密码成功",
Toast.LENGTH_SHORT).show();
Intent intent=new
Intent(ChangingPassword.this,NotesListActivity.class);
startActivity(intent);
finish();
}
}
});
}
@Override
public void onBackPressed(){
Intent intent=new Intent(ChangingPassword.this,NotesListActivity.class);
startActivity(intent);
finish();
}
}

@ -0,0 +1,65 @@
package net.micode.notes.ui;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import net.micode.notes.R;
public class DeletingPassword extends Activity {
EditText Dt_password;
Button Acknowledged;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_delete_password);
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
| WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
Dt_password=(EditText) findViewById(R.id.thepassword);
Acknowledged=(Button)findViewById(R.id.Dt_Acknowledged);
Acknowledged.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String text02 = Dt_password.getText().toString();
if(text02.equals("")==true)
Toast.makeText(DeletingPassword.this, "密码不能为空",
Toast.LENGTH_SHORT).show();
SharedPreferences pref=getSharedPreferences("user
management",MODE_PRIVATE);
String password = pref.getString("password","");
if(password.equals("")==false&&password.equals(text02)==true){
SharedPreferences.Editor editor=getSharedPreferences("user
management",
MODE_PRIVATE).edit();
editor.putBoolean("user",false);//false 表示已经设置登录密码
editor.putString("password","");
editor.apply();
Toast.makeText(DeletingPassword.this, "已经删除登录密码",
Toast.LENGTH_SHORT).show();
Intent intent=new
Intent(DeletingPassword.this,NotesListActivity.class);
startActivity(intent);
finish();
}
else{
Toast.makeText(DeletingPassword.this, "密码错误",
Toast.LENGTH_SHORT).show();
Dt_password.setText("");//把密码框内输入过的错误密码清空
}
}
});
}
@Override
public void onBackPressed() {
Intent intent=new Intent(DeletingPassword.this,NotesListActivity.class);
startActivity(intent);
finish();
}
}

@ -0,0 +1,54 @@
package net.micode.notes.ui;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import net.micode.notes.R;
public class LoginActivity {
EditText lgn_password;
Button lgn_login;
@Override
protected void onCreate(Bundle saverInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences pref = getSharedPreferences("user managemet", MODE_PRIVATE);
boolean User_boolean = pref.getBoolean("user", false); //检查用户是否设置了密码
if (!User_boolean) { //如果用户没有设置密码,则直接跳转到便签主界面
Intent intent = new Intent(LoginActivity.this, NotesListActivity.class);
startActivity(intent);
finish();
}
setContentView(R.layout.activity_login);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
lgn_password = (EditTExt) findViewById(R.id.lgn_password);
lgn_login = (Button) findViewById(R.id.login);
lgn_login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences pref = getSharedPreferences("user management", MODE_PRIVATE);
String password = pref.getString("password", "");
if (password.equals(" ") == false && password.equals(lgn_password.getText().toString()) == true) {
Intent intent = new Intent(LoginActivity.this, NotesListActivity.class);
startActivity(intent);
finish();
} else {
Toast.makeText(LoginActivity.this, "密码错误", Toast.LENGTH_SHORT).show();
lgn_password.setText(""); //清空密码框内的输入
}
}
}
);
}
}

@ -0,0 +1,66 @@
package net.micode.notes.ui;
import static android.content.Context.MODE_PRIVATE;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import net.micode.notes.R;
public class SettingPassword extends Activity {
EditText password;
EditText password_ack;
Button acknowledge;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_set_loginpassword);
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
| WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
password = (EditText) findViewById(R.id.password);
password_ack = (EditText) findViewById(R.id.password_ack);
acknowledge = (Button)findViewById(R.id.acknowledge);
acknowledge.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String text02 = password.getText().toString();
String text03 = password_ack.getText().toString();
if(text02.equals("")==true) {
Toast.makeText(SettingPassword.this, "密码不能为空", Toast.LENGTH_SHORT).show();
}
else if (text02.equals(text03) == false) {
Toast.makeText(SettingPassword.this, "密码错误,请重新输入密码 ", Toast.LENGTH_SHORT).show();
password_ack.setText("");
}
else if (text02.equals(text03) == true){
SharedPreferences.Editor editor=getSharedPreferences("user management", MODE_PRIVATE).edit();
editor.putBoolean("user",true); //true 表示已经设置登录密码
editor.putString("password",text02);
editor.apply();
Log.d("RegisterLoginPassword","password is "+text02);
Toast.makeText(SettingPassword.this, "密码设置成功",
Toast.LENGTH_SHORT).show();
Intent intent=new
Intent(SettingPassword.this,NotesListActivity.class);
startActivity(intent);
finish();
}
}
});
}
@Override
public void onBackPressed() {
Intent intent=new Intent(SettingPassword.this,NotesListActivity.class);
startActivity(intent);
finish();
}
}
Loading…
Cancel
Save