1. 程式人生 > >【轉·開發技術】C#實現 [忘記密碼] 通過【郵箱取回密碼】功能

【轉·開發技術】C#實現 [忘記密碼] 通過【郵箱取回密碼】功能

內容概括:通過引用Jmail元件實現 “通過郵箱找回密碼” 功能

前端頁面程式碼

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
 <html xmlns="http://www.w3.org/1999/xhtml" >
 <head id="Head1" runat="server">
 <title>個人會員密碼找回</title>
 <link href="/style.css" rel="stylesheet" type="text/css" />
 <script language="javascript" type="text/javascript">
 // 檢查 E-mail 是否已被註冊
 function CheckEmail()
 {
 var e = document.getElementById("email").value;
 if(e != "")
 {
 if(!/(\S)+[@]{1}(\S)+[.]{1}(\w)+/.test(e)) 
 {
 alert("請輸入格式正確的E-mail 地址!");
 var email = document.getElementById ( "email" );
 email.value = "";
 email.focus ();
 } 
 } 
 }
 
 function checkAll()
 {
 var ee = document.getElementById("username").value;
 if(ee == "")
 {
 alert('登入名稱不能為空');
 return false; 
 }
 
 var e = document.getElementById("email").value;
 if(e == "")
 {
 alert('Emial不能為空');
 return false; 
 }
 
 
 }
 
 </script>
 </head>
 <body>
 <form id="form1" runat="server">
 <div> 
 <table width="778" border="0" align="center" cellpadding="5" cellspacing="0" class="table_huang">
 <tr>
 <td colspan="2" class="TD_huang_14_write"> <span style="font-size: 11pt">>> 獲取密碼</span></td>
 </tr>
 <tr>
 <td width="26"></td>
 <td width="724"><table width="90%" border="0" cellspacing="2" cellpadding="5">
 <tr>
 <td width="23%"><div align="right">使用者名稱:</div></td>
 <td width="77%">
 <asp:TextBox ID="username" runat="server" Width="150px" ></asp:TextBox></td>
 </tr>
 <tr>
 <td><div align="right">註冊時填寫的Email:</div></td>
 <td>
 <asp:TextBox ID="email" runat="server" Width="200px" ></asp:TextBox></td>
 </tr>
 <tr>
 <td><div align="right">驗證碼:</div></td>
 <td><table width="100%">
 <tr>
 <td align="left" valign="top" style="width: 64px"><asp:TextBox ID="txt_validcode" runat="server" Height="15px" Width="62px"></asp:TextBox> </td>
 <td align="left" valign="top"><img id="yzm" src="../ValidateCode.aspx" /></td>
 </tr>
 </table></td>
 </tr>
 <tr>
 
 <td colspan="2" style="text-align: center">
 <asp:Button ID="Button1" runat="server" Text=" 找回密碼 " /></td>
 </tr>
 </table> </td>
 </tr>
 </table> 
 </div>
 </form>
 </body>
 </html>

後端程式碼
using System;
 using System.Data;
 using System.Configuration;
 using System.Collections;
 using System.Web;
 using System.Web.Security;
 using System.Web.UI;
 using System.Web.UI.WebControls;
 using System.Web.UI.WebControls.WebParts;
 using System.Web.UI.HtmlControls;
 
 
 
 public partial class ClientServer_Default2 : System.Web.UI.Page
 {
 string lspass = "";
 
 protected void Page_Load(object sender, EventArgs e)
 {
 if (!IsPostBack)
 {
 this.Button1.Attributes.Add("onclick", "javascript:return checkAll();");
 }
 
 }
 protected void Button1_Click(object sender, EventArgs e)
 {
 HttpCookie myCookie_validcode = Request.Cookies["FWCX_CheckCode"];
 if (myCookie_validcode.Value.ToString() != txt_validcode.Text)
 {
 Response.Write("<script>");
 Response.Write("alert('驗證碼錯誤')");
 Response.Write("</script>");
 return;
 }
 
 //首先判斷該登入名稱和email是否存在
 string sql = "select * from t_users where u_username='" + username.Text.Trim() + "' and u_email='" + email.Text.Trim() + "' and u_class='0' and u_valid='1'";
 DataTable dt = new DataTable();
 //dt = new SQLTool().dataTable(sql);
 
 if (dt.Rows.Count < 1)
 {
 Response.Write("<script>alert('登入名稱或Email地址錯誤!,請重新填寫後再試。');</script>");
 
 }
 else
 {
 //首先給現在的資料庫t_users附上一個臨時密碼
 //Response.Write(CreateRandomCode(8));
 lspass = CreateRandomCode(8);
 sql = "update t_users set u_getpwd='" + lspass + "' where u_username='" + username.Text.Trim() + "' and u_email='" + email.Text.Trim() + "' and u_class='0' and u_valid='1'";
 //if (new SQLTool().ExecuteSql(sql) >= 0)
 //{
 sendEmail(email.Text.Trim(), username.Text.Trim());
 Response.Write("<script>alert('臨時密碼已經發送到您的註冊Email中,請在下一頁面中修改密碼。');window.location.href='getpwdconfirm.aspx';</script>");
 //}
 }
 }
 public void sendEmail(string email, string name)
 {
 try
 {
 jmail.Message jmessage = new jmail.Message();
 jmessage.Charset = "GB2312";
 jmessage.From = "
[email protected]
"; // 發信地址 jmessage.MailServerUserName = "86085005"; //smtp認證使用者名稱(注:如為網易使用者,不加要@163.com,只要前面部分即可) jmessage.MailServerPassWord = "kingseer"; // smtp論證使用者名稱密碼 jmessage.FromName = "108人力銀行"; // 發信人 jmessage.ReplyTo = "[email protected]"; // 回覆地址 jmessage.C;//郵件內容為html jmessage.Subject = "108人力銀行臨時密碼"; string strbody = ""; strbody += new functions().getInfoXX("t_pagetexts", "p_name", "找回密碼郵件反饋-個人", "p_value").Replace("$", name).Replace("@%", lspass); jmessage.HTMLBody = strbody; // 郵件標題 jmessage.AddRecipient(email, "", ""); jmessage.Send("smtp.163.com", false);//傳送郵件smtp.163.com jmessage.Close();//關閉物件,釋放資源 } catch (Exception err) { Response.Write(err); } } /// <summary> /// 功能:產生數字和字元混合的隨機字串 /// </summary> /// <param name="codecount">字串的個數</param> /// <returns></returns> private string CreateRandomCode(int codecount) { // 數字和字元混合字串 string allchar = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n"; //分割成陣列 string[] allchararray = allchar.Split(','); string randomcode = ""; //隨機數例項 System.Random rand = new System.Random(unchecked((int)DateTime.Now.Ticks)); for (int i = 0; i < codecount; i++) { //獲取一個隨機數 int t = rand.Next(allchararray.Length); //合成隨機字串 randomcode += allchararray[t]; } return randomcode; } }


以上內容轉載自部落格

相關推薦

·開發技術C#實現 [忘記密碼] 通過郵箱取回密碼功能

內容概括:通過引用Jmail元件實現 “通過郵箱找回密碼” 功能 前端頁面程式碼 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/

C#C#實現事務

identity title ini body pro 簡單例子 ear scalar 技術分享 1、創建事務的結構 SqlConnection sqlConnection = new SqlConnection(); ...初始化連

編譯原理c++實現自下而上語法分析器

不可 acm times style size PC -i 表達式 鏈接 寫在前面:本博客為本人原創,嚴禁任何形式的轉載!本博客只允許放在博客園(.cnblogs.com),如果您在其他網站看到這篇博文,請通過下面這個唯一的合法鏈接轉到原文! 本博客全網唯一合法URL:ht

微信小程式c# 實現獲取openid、session_key 服務端

c#寫一個獲取微信小程式 openid和session_key 的方法。。 1,微信小程式端 // 登入 wx.login({ success: res => { // 傳送 res.code 到後臺換取 openId, sessionKey,

大二上期資料結構實驗記錄(二)初版C實現簡單一元多項式加減乘求導及代值計算(有借鑑刪改)

想要記錄自己程式設計思維的成長所以發到部落格,歡迎並且感激大家指出缺點和錯誤! 一、【實驗構思(Conceive)】 本次實驗要求是用C或C++語言設計並實現一個一元稀疏多項式的簡單計算器,要求是要有如下功能 1、輸入並建立多項式 2、輸出多項式,序列按指數降序

c++鞏固練習c++實現日期計算器、日期萬年曆(日期類)

<pre class="cpp" name="code">#include "Date.h" bool Date::operator==(const Date& d) { return _year==d._year && _month==d._month &&a

記錄c++實現json格式解析與轉換

水群的時候看到有人在說bat讀json資料,突然就想寫一個json解析的bat第三方。。。 json語法比較簡單,於是就用有限狀態機來實現了。 下面是轉換效果(左邊是json資料,右邊是轉換為bat命令的結果): 順便實現了語法錯誤提示:

C/C++C實現gzip格式的壓縮與解壓Demo

參考連結:  http://www.codeproject.com/Questions/341319/C-Decompress-Gzipped-http-response http://www.cppblog.com/woaidongmao/archive/2011/06/

VS2015c++實現windows系統版本、型別、語言識別

 一、VS2015 新建專案->win32 控制檯應用程式 1.以下操作實現跨平臺 (1).配置屬性-常規-MFC的使用->使用標準Windows庫或者在靜態庫中使用MFC (2).配置屬性-c/c++-程式碼生成-執行庫->多執行緒(/MT) 二.

Linux開發技術之常見問題一個建立執行緒時常見的問題:invalid conversion from `void*' to `void*(*)(void*)

void main_thread ( void *ptr ) {   char *message1 = "Thread 1";   char *message2 = "Thread 2";   pthread_t thread3, thread4;   int iret3, iret4;  

C++c++實現線性表、連結串列

c++實現動態順序表如下 typedef int DataType; class SeqList { public: //////////////類的基本成員函式定義///////////////// SeqList()

劍指offer第六題旋轉陣列的最小數字c++實現

題目描述 把一個數組最開始的若干個元素搬到陣列的末尾,我們稱之為陣列的旋轉。輸入一個非遞減序列的一個旋轉,輸出旋轉陣列的最小元素。例如陣列{3,4,5,1,2}為{1,2,3,4,5}的一個旋轉,該陣列的最小值為1。 本題給的也算是有序數列,一看就應該和二分沾邊,事實也是這樣。 題目給的是非遞減序列,就是

演算法導論c++實現計數排序

計數排序的基本思想為:對每一個輸入的元素x,確定出小於x的元素的個數。有了這一資訊,那麼就可以把x直接放到相應的位置上。 特點: 1 需要臨時的儲存空間,如果排序資料範圍特別大時,空間開銷很大。 2 適合於排序0 - 100以內的資料。 3 排序的時間複雜度為O(n)。 #

C#實現語音視訊錄製 基於MCapture + MFile

在上一篇使用C#採集語音視訊、螢幕桌面【基於MCapture元件】的文章中,我們已經可以採集到語音、視訊、桌面資料了,那麼,接下來我們再結合MFile的錄製功能,便能把這些資料寫到檔案中,生成標準的mp4檔案。        使用MCapture+MFile,我們可以實現以下

C# 實現真正的WebCamera原創

近期,做了個小軟體,需要在Web頁面呼叫本地攝像頭,花了4個小時實現了(9個月沒寫程式了有點生疏了 ),現分享給大家,希望有人能夠用的到。     在網上也搜尋過好多的資料,基本上都是在WinForm實現的攝像頭呼叫,在頁面中呼叫的基本沒看見過。    思路:在頁面中呼叫A

原始碼C++實現嚴蔚敏資料結構所有演算法(一)線性表-順序表

日常說明:首先博主也是菜鳥一枚,有錯誤歡迎大家指正。另外本部落格所有的程式碼博主編寫後均除錯 通過。重要提醒!!!!博主使用的是VS2017,如果有低版本的小夥伴 最好新建空專案將此程式碼複製上去。 附加說明:最初的程式碼我沒有嚴格的按照專案規範來分離,希望

劍指offer第二十九題最小的K個數c++實現

題目描述 輸入n個整數,找出其中最小的K個數。例如輸入4,5,1,6,2,7,3,8這8個數字,則最小的4個數字是1,2,3,4,。 方法比較多,我直接用的set,然後取前k個就行了 vector<int> GetLeastNumbers_Solution(vector<int>

資料結構c++ 實現連結串列的建立,查詢,列印,刪除,插入

//程式很簡單,但是要捋順邏輯關係,留著備用 #include #include"stdafx.h" using namespace std; struct node { int data; node* next; }; node * created_hea

劍指offer第二十四題二叉樹中和為某一值的路徑c++實現

題目描述 輸入一顆二叉樹和一個整數,打印出二叉樹中結點值的和為輸入整數的所有路徑。路徑定義為從樹的根結點開始往下一直到葉結點所經過的結點形成一條路徑。 先序遍歷二叉樹,用一個數組記錄當前路徑,如果遍歷到葉子節點就進行判斷是否和給定值相等。 class Solution { public: vect

選擇排序C++實現選擇排序程式碼

#include<iostream> using namespace std; void print(int a[], int n) { for(int j= 0; j<n; j++) { cout<<a[j