连续好几天学习都没有什么进展,然而在今天这个烂漫的日子。突然有了学习的动力。想起来前几日老师给布置的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. Android SlidingMenu 仿网易新闻客户端布局

    前面两篇文章中的SlidingMenu都出现在左侧,今天来模仿一下网易新闻客户端左右两边都有SlidingMenu的效果,以下是网易新闻客户端效果: 不扯闲话了,直接进入正题吧 frame_conte ...

  2. select查询时,如何把指定的行放置在最前面

    可以用case when做一个列,然后根据这个列来排序,下面给出代码 ' end) as 'abc' from table order by abc

  3. Windows Azure Virtual Network (8) 创建Azure Point-to-Site点到站点 VPN

    <Windows Azure Platform 系列文章目录> 我们在使用Azure的时候,常常有这样的需求: -我需要将企业内网的主机连接到微软Azure公有云平台 -我需要保证企业内部 ...

  4. APP数据接口开发的一些经验

    刚接到这样的任务时,没有感觉到任何压力,不就是给移动端应用提供数据吗?那边发来参数,这边处理数据,返回JSON.做网站开发时经常使用ajax请求后台数据,不就是这么回事吗.于是,在确认完需求后就开始干 ...

  5. Android Studio的git功能的使用介绍

    本文介绍Android Studio(下面简称AS)中git工具的一些简单使用.因为AS为git的使用提供了很多人性化的图形界面操作,在很大程度上可以增加开发效率.本文面向新手,题主自己也是新手一枚, ...

  6. C# 6.0的字典(Dictionary)的语法

    在C# 6.0,当我们使用Dictionary时,我们可以使用新语法,来去简化程序以提高效率. public Dictionary<string, object> OldToolLocat ...

  7. 注意:DateTimePicker.Text不靠谱

    这鸟属性把我害苦过,特此敬告一下大家.具体表现在: 获取时:在DateTimePicker.ValueChanged事件中,获取到的Text有可能是string.Empty!!!,特别当ValueCh ...

  8. 基于吉日嘎拉的通用权限管理WebForm版扩展:字典选项管理和缓存管理

    关于字典管理,其实就是2个表,一个表记录字典和对应表,另一个表记录字典内容.我这里改名为字典选项,其实是一个意思.直接上图: 这里的字典选项是分子系统的,每个子系统可以有自己的单独字典,方便管理.但是 ...

  9. win10系统iis下部署搭建https (ssl/tls)本地测试环境

    有时想要把公司的某些XX项目部署成https站点,是为了在传输层加密传输,防止他人嗅探站点重要数据信息,平常我们使用的http方式都是明文方式传输的很不安全,容易被他人窃取.而有些时候要在本地搭建ht ...

  10. mysql易混淆知识点

    1,join 和 union join连接属于表之间的水平操作,而union 是表之间的垂直操作.简单讲就是水平操作主要是为了获得列数据,垂直操作是为了获得行数据 cross  join        ...