九、忘記密碼功能的實現

一、頁面設計

login頁面,和第二篇博文(用戶登錄和注冊)頁面基本一樣,只不過多了一個按鈕
其中忘記密碼?點我找回button3
在這里插入圖片描述
retrieve_password頁面
在這里插入圖片描述

change_password頁面
在這里插入圖片描述
頁面如下:
在這里插入圖片描述

二、數據庫

因為是忘記密碼,也就是修改密碼而已,數據表仍為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 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 = DateTime.Now.ToLocalTime().ToString();//string time = DateTime.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 SqlCommand(sqlSel, conn);if (Convert.ToInt32(cmd.ExecuteScalar()) > 0 )//賬號密碼正確{string sql = "select username,sex,phone from yy_user where username = '" + username + "'";SqlCommand com = new 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,phone, DateTime.Now.ToLocalTime());SqlCommand INSERT_cmd = new SqlCommand(INSERT_sql, conn);int count = INSERT_cmd.ExecuteNonQuery();if (count > 0){MessageBox.Show(name);MessageBox.Show("記錄用戶登錄!");new 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 Random();string str = null;for (int i = 0; i < 5; i++){int n = r.Next(0, 10);str += n;//包括字符串在內}identification = str;Bitmap b = new 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 Font(fonts[r.Next(0, 5)], 25, FontStyle.Bold);SolidBrush s = new SolidBrush(colors[r.Next(0, 5)]);//定義一個單獨的畫筆,使每個字符的顏色隨機Point p = new Point(i * 20, 0);//每個字符間隔20g.DrawString(str[i].ToString(), Font, s, p);}for (int a = 0; a < 5; a++){Point p1 = new Point(r.Next(0, b.Width), r.Next(0, b.Height));Point p2 = new Point(r.Next(0, b.Width), r.Next(0, b.Height));//線的兩點不能超過圖片的長和寬Pen pen = new Pen(Brushes.Cyan);//青色線段g.DrawLine(pen, p1, p2);}pictureBox1.Image = b;}private void button2_Click(object sender, EventArgs e){new Form1().Show();this.Hide();}private void button3_Click(object sender, EventArgs e){new 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 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 Random();string str = null;for (int i = 0; i < 5; i++){int n = r.Next(0, 10);str += n;//包括字符串在內}identification = str;Bitmap b = new 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 Font(fonts[r.Next(0, 5)], 25, FontStyle.Bold);SolidBrush s = new SolidBrush(colors[r.Next(0, 5)]);//定義一個單獨的畫筆,使每個字符的顏色隨機Point p = new Point(i * 20, 0);//每個字符間隔20g.DrawString(str[i].ToString(), Font, s, p);}for (int a = 0; a < 5; a++){Point p1 = new Point(r.Next(0, b.Width), r.Next(0, b.Height));Point p2 = new Point(r.Next(0, b.Width), r.Next(0, b.Height));//線的兩點不能超過圖片的長和寬Pen pen = new 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 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(phone_db);if(phone_db==phone){//conn.Close();MessageBox.Show("校驗通過");new change_password(username).Show();this.Hide();}else {MessageBox.Show("注冊手機號不對");}}else{MessageBox.Show("驗證碼輸入錯誤");}}private void button2_Click(object sender, EventArgs e){new 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 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 SqlCommand(sql, conn);com.ExecuteNonQuery();//返回值為操作的條數MessageBox.Show("修改成功");conn.Close();new login().Show();this.Hide();}}}
}

四、效果展示

程序運行
在這里插入圖片描述
登錄
在這里插入圖片描述
忘記密碼?點我找回
在這里插入圖片描述
在這里插入圖片描述
通過手機號來校驗
在這里插入圖片描述
驗證碼輸入錯誤
在這里插入圖片描述
調試時輸出數據庫中的注冊手機號
在這里插入圖片描述
與輸入框中的手機號對比
在這里插入圖片描述
校驗成功,跳轉到修改密碼change_password頁面
在這里插入圖片描述
兩次密碼必須一致
調試時,獲取登錄用戶的賬號
在這里插入圖片描述在這里插入圖片描述
在這里插入圖片描述

新密碼必須在3-16字符之間

修改成功
在這里插入圖片描述

點擊確定自動返回登錄頁面
在這里插入圖片描述
原始數據庫
在這里插入圖片描述
右擊yy_user
選擇前1000行
可看到密碼已經修改成功
在這里插入圖片描述

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/377678.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/377678.shtml
英文地址,請注明出處:http://en.pswp.cn/news/377678.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Android中對手機文件進行讀寫

參考張澤華視頻 &#xff08;一&#xff09;讀寫手機內存卡中的文件 對手機中的文件進行讀寫操作&#xff0c;或者新增一個文件時&#xff0c;可直接使用openFileOutput / openFileInput 得到文件的輸出、輸入流。 FileOutputStream fos this.openFileOutput("private.…

聯軸器選型_聯軸器| 軟件工程

聯軸器選型耦合 (Coupling) In general terms, the term coupling is defined as a thing that joins together two objects. If we talk about software development, then the term coupling is related to the connection between two modules, i.e. how tight interaction …

劍指 Offer 10- I. 斐波那契數列 (從重疊子問題到備忘錄到dp數組迭代解法)

目錄題目描述1、暴力遞歸法的重疊子問題2、備忘錄解法3、dp數組迭代算法4、滾動數組優化5、參考鏈接題目描述 寫一個函數&#xff0c;輸入 n &#xff0c;求斐波那契&#xff08;Fibonacci&#xff09;數列的第 n 項。斐波那契數列的定義如下&#xff1a; F(0) 0, F(1) 1 F…

C# 收郵件

C#沒有內置收郵件的類&#xff0c;參考網絡上的代碼&#xff0c;針對POP3協議服務器使用 Jmail組件來收郵件&#xff0c;針對IMAP協議服務器使用LumiSoft.Net 。 另外&#xff0c;一般免費郵箱需要在郵箱設置中開啟 POP3&#xff08;或IMAP&#xff09;、 SMTP服務才可以使用非…

HDU- 1754 I Hate It

http://acm.hdu.edu.cn/showproblem.php?pid1754 記住那讓自己wa的地方。 I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 29300 Accepted Submission(s): 11615 Problem Description很多學校流行…

mcq 隊列_MCQ | 軟件生命周期模型

mcq 隊列Q1. Which of the following models is best suited when the requirements of the software are not decided and also the user is not sure about how he wants the user interface to look like? Q1。 當不確定軟件的需求并且用戶不確定自己希望用戶界面看起來如何…

十、紡織品庫存管理系統全部功能展示

一、系統主頁面—Form1 系統運行加載頁面&#xff0c;主要包含三個功能&#xff0c;①登錄、②注冊、③退出系統 程序運行圖&#xff1a; 登錄功能&#xff0c;跳轉到登錄頁面 注冊功能&#xff0c;跳轉到注冊頁面 退出系統&#xff0c;程序結束運行 代碼如下&#xff1a; …

leetcode 376. 擺動序列 思考分析

目錄題目思路分析代碼總結題目 如果連續數字之間的差嚴格地在正數和負數之間交替&#xff0c;則數字序列稱為擺動序列。第一個差&#xff08;如果存在的話&#xff09;可能是正數或負數。少于兩個元素的序列也是擺動序列。 例如&#xff0c; [1,7,4,9,2,5] 是一個擺動序列&am…

[EF在VS2010中應用Entity framework與MySQL

在VS2010中應用Entity framework與MySQL 羅朝輝 (http://www.cnblogs.com/kesalin/) 本文遵循“署名-非商業用途-保持一致”創作公用協議本文講述了在VS2010中使用EF與MySQL的一個簡單示例。 工具安裝&#xff1a; 1&#xff0c;MySQL MySQL Community Server Connector/NET 6…

c++ cdi+示例_C ++“和”關鍵字示例

c cdi示例"and" is an inbuilt keyword that has been around since at least C98. It is an alternative to && (Logical AND) operator and it mostly uses with the conditions. “ and”是一個內置關鍵字&#xff0c;至少從C 98起就存在。 它是&&am…

Python上個手

Python&#xff0c;由吉多范羅蘇姆&#xff08;Guido van Rossum&#xff09;在1989打發圣誕節放假時間的一門“課余”編程項目&#xff0c;至今已有二十多年的歷史&#xff0c;語法簡潔清晰&#xff0c;深受喜愛&#xff1b; 小窺 # 查看版本 python -V # 輸出 print "he…

十、美化界面

一、背景圖片 二、透明化處理 BackColor—web—Transparent 三、數據庫建表語句 數據庫 USE [fiber_yy] GO /****** Object: Table [dbo].[yy_user_record] Script Date: 06/20/2022 18:54:48 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADD…

如何寫出優美的代碼(二)

&#xff08;本文思想基本來自于經典著作《重構》一書&#xff09; 上一篇 http://www.cnblogs.com/ceys/archive/2012/03/05/2379842.html#commentform 上一篇文章主要講了怎么給函數整容。現在我們大家基本上都使用面向對象語言&#xff0c;什么樣的“對象”才是優美的呢&…

轉:鏈表相交問題 詳解

源地址&#xff1a;http://blog.163.com/bbluesnow126/blog/static/27784545201251051156817/ 鏈表相交問題 2012-06-10 17:15:37| 分類&#xff1a; 算法 | 標簽&#xff1a;微軟面試題 |字號 訂閱 1、如何判斷一個單鏈表有環 2、如何判斷一個環的入口點在哪里 3、如何知…

VS 如何修改C++編譯標準

第一步&#xff0c;打開項目資源管理器的屬性頁面 第二步&#xff0c;選擇配置屬性->C/C>語言->C語言標準 第三步&#xff0c;選擇合適的標準&#xff0c;一般來說選最新即可

維吉尼亞密碼和一次性密碼本_密碼學中的一次性密碼

維吉尼亞密碼和一次性密碼本The One-time Pad cipher is almost similar to the Vernam cipher, as, like the vernam cipher, this cipher technique also encrypts the plain text by working on the binary level of the text. The only difference between the two is that…

十一、紡織面料下架功能的實現

一、數據庫 數據庫仍用yy_textile表&#xff0c;前幾篇博文都敘述過這里就不再敘述 在fiber_yy數據庫下創建yy_textile表 初始數據庫信息 二、頁面 admin_undercarriage 三、代碼實現 admin_undercarriage using System; using System.IO; using System.Data; using S…

svg和canvas的應用場景分析【轉載】

原文地址&#xff1a;http://blogs.msdn.com/b/weizhong/archive/2011/07/16/canvas-svg.aspx 思考什么時候使用Canvas 和SVG wzhong 15 Jul 2011 9:07 PM 0HTML5 Canvas 和 SVG 是 IE9 中引入的兩項令人激動的圖形功能。上周在拉斯維加斯舉辦的 MIX11 大會對這兩個功能進行了介…

【C++grammar】文件系統以及path類使用

目錄1.文件系統概述1、關于路徑2、如何將某個路徑下的所有文件遞歸地找出來&#xff1f;2.路徑類及操作1、path類的成員函數2、path類的非成員函數示例1&#xff1a;展示C17中的path對象的用法示例2&#xff1a;展示Path類中用于分解路徑成分的函數示例3&#xff1a;展示path相…

scala hashmap_如何在Scala中將Hashmap轉換為Map?

scala hashmapLets first understand what are maps and hashmaps? 首先讓我們了解什么是map和hashmap &#xff1f; map in Scala is a collection that stores its elements as key-value pairs, like a dictionary. Scala中的map是一個集合&#xff0c;將其元素存儲為鍵值…