大佬教程收集整理的这篇文章主要介绍了九、忘记密码功能的实现,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
login页面c;和第二篇博文(用户登录和注册)页面基本一样c;只不过多了一个按钮 其中忘记密码?点我找回 为button3
retrieve_password页面change_password页面
页面如下:因为是忘记密码c;也就是修改密码而已c;数据表仍为yy_user不变 id设置为主键自增
随便添加些数据login页面代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
namespace fiber_yy
{
public partial class login : Form
{
public String name = "";
public static String str_conn = "server=CY-20190824RMES;Initial Catalog=fiber_yy;User ID=sa;pwd=beyond";
SqlConnection conn = new @H_197_208@SqlConnection(str_conn);
public String identification = null;
public login()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)//登录
{
conn.Open();
String sex = "";
String phone = "";
String day = @R_616_7538@me.Now.ToLocalTime().ToString();
//String time = @R_616_7538@me.Now.ToLongtimestring().ToString();
String username = textBox1.Text;
String password = textBox2.Text;
String identify = textBox3.Text;
if (username.Equals("") || password.Equals("") || identify.Equals(""))
{
messageBox.Show("提示:请输入用户名、密码、验证码!", "警告");
}
else
{
String sqlSel = "select count(*) from yy_user where username = '" + username + "' and password = '" + password + "'";
SqlCommand cmd = new @H_197_208@SqlCommand(sqlSel, conn);
if (Convert.ToInt32(cmd.ExecuteScalar()) > 0 )//账号密码正确
{
String sql = "select username,sex,phone from yy_user where username = '" + username + "'";
SqlCommand com = new @H_197_208@SqlCommand(sql, conn);
SqlDataReader read = com.ExecuteReader();
while (read.Read())//获取yy_user表中的username,sex,phone
{
//int number = Convert.ToInt32(read["username"]);//查询列名1的数据,方法为: read(变量名)["列名"]; 该方法返回的是object类型
name = read["username"].ToString();
//messageBox.Show(Name);
sex = read["sex"].ToString();
//messageBox.Show(seX);
phone = read["phone"].ToString();
//messageBox.Show(phonE);
}
read.Close();
if (identify==identification)//判断验证码是否输入正确
{
String INSERT_sql = String.Format("INSERT INTO yy_user_record VALUES ('{0}','{1}','{2}','{3}')", name,sex,@H_883_47@phone, @R_616_7538@me.Now.ToLocalTime());
SqlCommand INSERT_cmd = new @H_197_208@SqlCommand(INSERT_sql, conn);
int count = INSERT_cmd.ExecuteNonQuery();
if (count > 0)
{
messageBox.Show(name);
messageBox.Show("记录用户登录!");
new @H_197_208@main_page().Show();
this.Hide();
}
else
{
messageBox.Show("记录用户失败");
}
}
else
{
messageBox.Show("验证码输入错误");
}
}
else
{
messageBox.Show("请检查账号密码");
}
}
}
private void pictureBox1_Click(object sender, EventArgs e)
{
Random r = new @H_197_208@Random();
String str = null;
for (int i = 0; i < 5; i++)
{
int n = r.Next(0, 10);
str += n;//包括字符串在内
}
identification = str;
Bitmap b = new @H_197_208@Bitmap(100, 15);
Graphics g = Graphics.FromImage(b);
for (int i = 0; i < 5; i++)
{
String[] fonts = { "宋体", "黑体", "隶书", "仿宋", "微软雅黑" };//字体数组
Color[] colors = { Color.Red, Color.Black, Color.Blue,Color.YellowGreen ,Color.Green };//颜色数组
Font f = new @H_197_208@Font(fonts[r.Next(0, 5)], 25, FontStyle.Bold);
SolidBrush s = new @H_197_208@SolidBrush(colors[r.Next(0, 5)]);//定义一个单独的画笔c;使每个字符的颜色随机
Point p = new @H_197_208@Point(i * 20, 0);//每个字符间隔20
g.DrawString(str[i].ToString(), Font, s, p);
}
for (int a = 0; a < 5; a++)
{
Point p1 = new @H_197_208@Point(r.Next(0, b.Width), r.Next(0, b.Height));
Point p2 = new @H_197_208@Point(r.Next(0, b.Width), r.Next(0, b.Height));//线的两点不能超过图片的长和宽
Pen pen = new @H_197_208@Pen(Brushes.Cyan);//青色线段
g.DrawLine(pen, p1, p2);
}
pictureBox1.Image = b;
}
private void button2_Click(object sender, EventArgs e)
{
new @H_197_208@Form1().Show();
this.Hide();
}
private void button3_Click(object sender, EventArgs e)
{
new @H_197_208@retrieve_password().Show();
this.Hide();
}
}
}
retrieve_password页面代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
namespace fiber_yy
{
public partial class retrieve_password : Form
{
public String name = "";
public static String str_conn = "server=CY-20190824RMES;Initial Catalog=fiber_yy;User ID=sa;pwd=beyond";
SqlConnection conn = new @H_197_208@SqlConnection(str_conn);
public String identification = null;
public String phone = "";
public String phone_db = "";
public String username = "";
public String username_db = "";
public String identify = "";
public retrieve_password()
{
InitializeComponent();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
Random r = new @H_197_208@Random();
String str = null;
for (int i = 0; i < 5; i++)
{
int n = r.Next(0, 10);
str += n;//包括字符串在内
}
identification = str;
Bitmap b = new @H_197_208@Bitmap(100, 15);
Graphics g = Graphics.FromImage(b);
for (int i = 0; i < 5; i++)
{
String[] fonts = { "宋体", "黑体", "隶书", "仿宋", "微软雅黑" };//字体数组
Color[] colors = { Color.Red, Color.Black, Color.Blue, Color.YellowGreen, Color.Green };//颜色数组
Font f = new @H_197_208@Font(fonts[r.Next(0, 5)], 25, FontStyle.Bold);
SolidBrush s = new @H_197_208@SolidBrush(colors[r.Next(0, 5)]);//定义一个单独的画笔c;使每个字符的颜色随机
Point p = new @H_197_208@Point(i * 20, 0);//每个字符间隔20
g.DrawString(str[i].ToString(), Font, s, p);
}
for (int a = 0; a < 5; a++)
{
Point p1 = new @H_197_208@Point(r.Next(0, b.Width), r.Next(0, b.Height));
Point p2 = new @H_197_208@Point(r.Next(0, b.Width), r.Next(0, b.Height));//线的两点不能超过图片的长和宽
Pen pen = new @H_197_208@Pen(Brushes.Cyan);//青色线段
g.DrawLine(pen, p1, p2);
}
pictureBox1.Image = b;
}
private void button1_Click(object sender, EventArgs e)
{
username = textBox1.Text;
phone = textBox2.Text;
identify = textBox3.Text;
//messageBox.Show(identify);
//messageBox.Show(identification);
if (identify == identification)//判断验证码是否输入正确
{
conn.Open();
String sql = "select username,phone from yy_user where username = '" + username + "'";
SqlCommand com = new @H_197_208@SqlCommand(sql, conn);
SqlDataReader read = com.ExecuteReader();
while (read.Read())//获取yy_user表中的username,sex,phone
{
//int number = Convert.ToInt32(read["username"]);//查询列名1的数据,方法为: read(变量名)["列名"]; 该方法返回的是object类型
username_db = read["username"].ToString();
//messageBox.Show(Name);
//sex = read["sex"].ToString();
//messageBox.Show(seX);
phone_db = read["phone"].ToString();
//messageBox.Show(phonE);
}
read.Close();
messageBox.Show(@H_883_47@phone_db);
if(@H_883_47@phone_db==@H_883_47@phone)
{
//conn.Close();
messageBox.Show("校验通过");
new @H_197_208@change_password(username).Show();
this.Hide();
}
else
{
messageBox.Show("注册手机号不对");
}
}
else
{
messageBox.Show("验证码输入错误");
}
}
private void button2_Click(object sender, EventArgs e)
{
new @H_197_208@login().Show();
this.Hide();
}
}
}
change_password页面代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
namespace fiber_yy
{
public partial class change_password : Form
{
public String name = "";
public static String str_conn = "server=CY-20190824RMES;Initial Catalog=fiber_yy;User ID=sa;pwd=beyond";
SqlConnection conn = new @H_197_208@SqlConnection(str_conn);
//public String identification = null;
public String password = "";
public String password1 = "";
public String username = "";
//OleDbCommand cmd = new OleDbCommand();
//cmd.Connection = conn;
public change_password()
{
InitializeComponent();
}
public change_password(String yy)
{
InitializeComponent();
username = yy;
}
private void button1_Click(object sender, EventArgs e)
{
messageBox.Show(username);
password = textBox1.Text;
password1 = textBox2.Text;
if (password.Length <= 3 || password.Length >= 16)
{
label3.Text = "密码长度应该在3~16字符之间";
}
else if(password != password1)
{
label3.Text = "两次输入密码不一致";
//messageBox.Show("两次输入密码不一致");
}
else if(password==password1)
{
conn.Open();
String sql = "update yy_user set password = '"+ password + "' where username = '" + username + "'";
SqlCommand com = new @H_197_208@SqlCommand(sql, conn);
com.ExecuteNonQuery();//返回值为操作的条数
messageBox.Show("修改成功");
conn.Close();
new @H_197_208@login().Show();
this.Hide();
}
}
}
}
程序运行
登录 忘记密码?点我找回 通过手机号来校验 验证码输入错误 调试时输出数据库中的注册手机号 与输入框中的手机号对比@H_607_3176@
校验成功c;跳转到修改密码change_password页面 两次密码必须一致 调试时c;获取登录用户的账号新密码必须在3-16字符之间
修改成功
@H_758_3197@
点击确定自动返回登录页面
原始数据库 右击yy_user表 选择前1000行 可看到密码已经修改成功以上是大佬教程为你收集整理的九、忘记密码功能的实现全部内容,希望文章能够帮你解决九、忘记密码功能的实现所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。