连续好几天学习都没有什么进展,然而在今天这个烂漫的日子。突然有了学习的动力。想起来前几日老师给布置的android忘记密码的功能实现。今天也有了想法。就是按照老师的建议,简单的回答一个问题,实现此功能。我就模仿之前写的登录的例子。实现了此功能。我的想法是:回答之前绑定的手机号。如果正确则忘记密码成功。反之失败。

现在开始上效果图片:

android端的代码:

ForgetActivity.java

package com.itcast.forget;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL; import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.content.Intent;
import android.text.TextUtils;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast; public class ForgetActivity extends Activity {
private EditText et_phone;
protected static final int ERROR = 2;
protected static final int SUCCESS = 1;
private Handler handler = new Handler(){
public void handleMessage(Message msg) {
switch (msg.what) {
case SUCCESS:
Toast.makeText(ForgetActivity.this,(String)msg.obj, 1).show(); break; case ERROR:
Toast.makeText(ForgetActivity.this,"失败", 1).show();
break; }
};
}; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_forget);
et_phone = (EditText) findViewById(R.id.et_phone);
} public void btn_ok(View view){
final String phone = et_phone.getText().toString().trim();
if (TextUtils.isEmpty(phone)) {
Toast.makeText(this, "手机号不能为空!", 0).show();
return;
}
new Thread(){
public void run(){
try{
String path = "http://192.168.1.105:80/xampp/forget.php";
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("User-Agent", "Mozilla/5.0(compatible;MSIE 9.0;Windows NT 6.1;Trident/5.0)");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");//请求的类型 表单数据
String data = "phone="+phone+"&button=";
conn.setRequestProperty("Content-Length", data.length()+"");//数据的长度
conn.setDoOutput(true);//设置向服务器写数据
byte[] bytes = data.getBytes();
conn.getOutputStream().write(bytes);//把数据以流的方式写给服务
int code = conn.getResponseCode();
if(code == 200){
InputStream is = conn.getInputStream();
String result = StreamTools.readStream(is);
Message mas= Message.obtain();
mas.what = SUCCESS;
mas.obj = result;
handler.sendMessage(mas); }else{
Message mas = Message.obtain();
mas.what = ERROR;
handler.sendMessage(mas);
} }catch(Exception e){
Message mas = Message.obtain();
mas.what = ERROR;
handler.sendMessage(mas);
}
};
}.start();
} }

MainActivity.java


package com.itcast.forget;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button; public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
} public void forget(View view){
Intent intent = new Intent(this,ForgetActivity.class);
startActivity(intent);
} }

StreamTools.java

package com.itcast.forget;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream; public class StreamTools { public static String readStream(InputStream is){
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = -1;
while ((len = is.read(buffer))!=-1) {
baos.write(buffer,0,len);
}
baos.close();
return new String(baos.toByteArray());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "";
}
}
}

activity_forget.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#E6E6E6" android:orientation="vertical" > <TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_margin="10dp"
android:text="请输入您当时绑定的手机号:" /> <EditText
android:id="@+id/et_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:inputType="phone" > </EditText> <Button
android:onClick="btn_ok"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#3C8DC4"
android:textColor="#FFFFFF"
android:text="确定" /> </LinearLayout>

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E6E6E6"
android:orientation="vertical">
<ImageView
android:id="@+id/iv_head"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:src="@drawable/ic_launcher"/>
<LinearLayout
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/iv_head"
android:layout_margin="10dp"
android:background="#FFFFFF"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/rl_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="账号"/>
<EditText
android:id="@+id/et_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@+id/tv_name"
android:background="@null"/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#E6E6E6"/>
<RelativeLayout
android:id="@+id/rl_userpsd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<TextView
android:id="@+id/tv_psw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="密码"/>
<EditText
android:id="@+id/et_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@+id/tv_psw"
android:inputType="textPassword"
android:background="@null"/>
</RelativeLayout> </LinearLayout>
<Button
android:onClick="login"
android:id="@+id/btn_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/layout"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:background="#3C8DC4"
android:text="登录"
android:textColor="#FFFFFF"/> <Button
android:onClick="forget"
android:id="@+id/btn_forget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_below="@+id/btn_login"
android:background="#E6E6E6"
android:text="忘记密码" /> </RelativeLayout>
添加权限:

<uses-permission android:name="android.permission.INTERNET"/>

PHP代码:

<?php
if(isset($_POST['button'])){
$phone=$_POST['phone'];//得到用户输入的手机号
if($phone == "123456"){//假设用户的手机号为123456
echo '哈哈。。。成功忘记密码';
}else{
echo '操作失败!';
}
}else{
echo 'test!';
}
?>

Android忘记密码功能实现的更多相关文章

  1. C#.NET 大型通用信息化系统集成快速开发平台 4.1 版本 - 忘记密码功能改进、手机短信、电子邮件

    由于我们的系统接近有100000个用户账户,经常会有忘记密码的时候,用户多了,很小的一个功能,每天都会有很多人在用,每个功能都非常友善,会提高提系统的效率,提高用户体验. 一天最多能返回3次手机短信, ...

  2. Android找回密码功能 手机找回、邮箱找回

    找回密码功能设计:https://blog.csdn.net/qq_33472765/article/details/82287404?utm_source=blogxgwz0 手机找回:https: ...

  3. asp.net忘记密码功能

    //调用接口 post public string GetResponseByPost(string mobile, string messcode, string values, string ut ...

  4. android: SharedPreferences实现记住密码功能

    既然是实现记住密码的功能,那么我们就不需要从头去写了,因为在上一章中的最佳实 践部分已经编写过一个登录界面了,有可以重用的代码为什么不用呢?那就首先打开 BroadcastBestPractice 项 ...

  5. java web实现 忘记密码(找回密码)功能及代码

    java web实现 忘记密码(找回密码)功能及代码 (一).总体思路 (二).部分截图 (三).部分代码 (一).总体思路: 1.在 找回密码页面 录入 姓名.邮箱和验证码,录入后点击[提交]按钮, ...

  6. Android 开发笔记___SQLite__优化记住密码功能

    package com.example.alimjan.hello_world; /** * Created by alimjan on 7/4/2017. */ import com.example ...

  7. django 开发忘记密码通过邮箱找回功能

    一.流程分析: 1.点击忘记密码====>forget.html页面,输入邮箱和验证码,发送验证链接网址的邮件====>发送成功,跳到send_success.html提示 2.到邮箱里找 ...

  8. Android忘记锁屏密码如何进入手机?

    Android忘记锁屏密码如何进入手机?     1.关闭手机 2.进入recovery模式(即恢复模式,记住不是挖煤模式.进入恢复模式不同手机有不同方法,三星的话安主页键,关机键和音量+(或-键), ...

  9. Android实战(一)学习了多个控件实现登录及记住密码功能

    首先确定一下需要的控件: 两个EditText:用于输入账号和密码 一个button:用于登录查看账号和密码是否正确 一个checkbox:用于记住密码和账户 一个Androidstudio:用于编写 ...

随机推荐

  1. SQL Server代理(10/12):使用代理账号运行作业

    SQL Server代理是所有实时数据库的核心.代理有很多不明显的用法,因此系统的知识,对于开发人员还是DBA都是有用的.这系列文章会通俗介绍它的很多用法. 在这一系列的上一篇,你查看了msdb库下用 ...

  2. 矢量Chart图表嵌入HTML5网络拓扑图的应用

    使用 HT for Web (以下简称 HT)开发HTML5网络拓扑图的开发者有 Chart 需求的项目的时候,感觉很痛苦,HT 集成的 Chart 组件中,并不包含有坐标,在展现方面不是很直观,但是 ...

  3. Git 查看文件的历史

    用惯了tfs,刚一接触git感觉很不顺手,特别是一些很基本的操作,用起来都怪怪的(可能是不习惯命令行的原因吧).下面把查看文件历史的用例小结一下. 查看某个文件的修改历史 在git中查看历史的命令主要 ...

  4. JAVA - IDEA快捷键(精简版)

    快捷键 功能 Ctrl + Alt + V 对应eclipse ctrl + l + 2 自动补全 Ctrl + Alt + L 对应eclipse ctrl + shift + o 代码格式化 Ct ...

  5. ASP.NET Core 开发-Entity Framework (EF) Core 1.0 Database First

    ASP.NET Core 开发-Entity Framework Core 1.0 Database First,ASP.NET Core 1.0 EF Core操作数据库. Entity Frame ...

  6. 关于JQuery(最后一点动画效果*)

    1,$(':radio').val(['1','2','3']);//特殊写法,把值为1 2 3的都选中. 2,math.abs(len)取绝对值 3,按钮高亮显示,一般是配置两个按钮,一个普通的,一 ...

  7. UML类图画法及其之间关系

    1.泛化又名继承(Generalization),带空心箭头的实线表示,箭头指向父类 2.实现(Realization),带空心的虚线表示 3.关联(Association),类与类之间的关联,它使一 ...

  8. RARP反向地址转换协议

    反向地址转换协议(RARP:Reverse Address Resolution Protocol) 反向地址转换协议(RARP)允许局域网的物理机器从网关服务器的 ARP 表或者缓存上请求其 IP ...

  9. 【书籍下载链接】_1_第一轮_C语言书籍

    各位朋友,如果您觉得下载的电子书,看的还可以,请购买纸质版的图书,如果您觉得 您下载的书,不值得一看请在下载后直接删除. Windows汇编:http://dl.vmall.com/c0jk1v970 ...

  10. Gym 101102D---Rectangles(单调栈)

    题目链接 http://codeforces.com/gym/101102/problem/D problem  description Given an R×C grid with each cel ...