Stmp email sendingGenerate random numberAddition and subtraction of Serv-U6.0.0.2AlgorithmImage ScalingBase64 encoding and decoding
// Response. Write (Sendmail ("theme", "admin@admin.com", "test@test.com", "body! "); // Call
Public StringSendmail ( StringSubject,StringForm,StringTo,String Body)
{
// Subject content
String Tform, role, mailerr;
// Compare whether the domain name is the same-if the recipient's domain name is the same, the call cannot be sent successfully!
Tform = RegEx. Replace (form ,".*@","");
Bytes= RegEx. Replace (,".*@","");
If (Tform. tolower ()! = Lower. tolower ())
{
Mailerr = "sent successfully! ";
Try {
Try {
Mailmessage mymail = new mailmessage ();
Mymail. bodyformat = mailformat. html;
Mymail. Subject = subject;// Subject
Mymail. From = form; // Sender's email
Mymail. To =; // Recipient email
// Mymessage. Cc = body; // copy
Mymail. Body = body; // Body content
Try {
// Smtpmail. smtpserver = "localhost"; // set the eamil sending server. If this parameter is not set, the local machine is used by default.
Smtpmail. Send (mymail ); // Send
}
Catch (System. Web. httpexception ehttp)
{
Mailerr ="<A style = 'color: # ff0000; font-size: 12px; '> "+ Ehttp. Message +" The following is a complete error message: ";
Mailerr + =" </A> <br> <HR> <br> <a style = 'font-size: 12px; '> "+ Ehttp. tostring () +" </A> ";
}
}
Catch (Indexoutofrangeexception ){
Mailerr =" <A style = 'color: # ff0000; font-size: 12px; '> error: Incorrect email address! </A> ";
}
}
Catch (System. Exception e ){
Mailerr =" <A style = 'color: # ff0000; font-size: 12px; '> "+ E. Message +" The following is a complete error message: ";
Mailerr + ="</A> <br> <HR> <br> <a style = 'font-size: 12px; '> "+ E. tostring () +" </A> ";
}
}
Else
Mailerr =" The domain name of the recipient cannot be the same' "+ Tform +" ! ";
Return Mailerr;
}
// Generate a random number
Public String Makepassword ()
{
Int pwdlen = 2; // Generate the digits of random characters
String Pwdchars = "Abcdefghijklmnopkrstuvwxyzzbcdefghijklmnopkrstuvwxyz" ; // The generated character contains the word
String Tmpstr = "";
Int Irandnum;
Random RND = new random ();
For (INT I = 0; I <pwdlen; I ++)
{
Irandnum = RND. Next (pwdchars. Length );
Tmpstr + = pwdchars [irandnum];
}
Return Tmpstr;
}
// Algorithm for addition and subtraction of Serv-U6.0.0.2
<% @ Import namespace = "system. Data" %>
<% @ Import namespace = "system. Data. sqlclient" %>
<% @ Import namespace = "system. Web. Security" %>
<Script language = "C #" runat = "server">
Public void yanzheng (Object sender, system. eventargs E)
{
String A = open (username. Text, userpassword. Text );
String B;
If (A = "1") response. Write ("this account is not available" + username. Text );
Else
{
B = jiami (A, userpassword. Text );
If (A = B) response. Write ("OK! Password: <br> "+ B );
Else response. Write ("Incorrect:" + B + "<br> correct password:" + );
}
}
Public void new (Object sender, system. eventargs E)
{
Sqlconnection conn = new sqlconnection ("Server = (local); Integrated Security = sspi; database = Serv-U ");
Sqlcommand cmd = new sqlcommand ("Update [useraccounts] Set Password = @ password where name = @ name", Conn );
Cmd. Parameters. Add (New sqlparameter ("@ name", sqldbtype. nvarchar, 40 ));
Cmd. Parameters. Add (New sqlparameter ("@ password", sqldbtype. nvarchar, 40 ));
Cmd. Parameters ["@ name"]. value = username. text;
Cmd. Parameters ["@ password"]. value = newmima (newuserpassword. Text );
Cmd. Connection. open ();
Cmd. executenonquery ();
Response. Write ("modified successfully ");
Cmd. Connection. Close ();
}
Public String open (string username, string userpassword) // check whether this account exists. If yes, 1 is returned and the original password is assigned to the password.
{
Sqlconnection conn = new sqlconnection ("Server = (local); Integrated Security = sspi; database = Serv-U ");
Sqlcommand cmd = new sqlcommand ("select top 1 [name], [Password] from [useraccounts] Where name = '" + username + "'", Conn );
Conn. open ();
Sqldatareader DR = cmd. executereader ();
If (dr. Read ())
{
Userpassword = Dr ["password"]. tostring ();
Conn. Close ();
Return userpassword;
}
Else
{
Conn. Close ();
Return "1 ";
}
}
Public String jiami (string userpassword, string password) // encrypt the first two digits of the original password
{
String password2 = userpassword. substring (0, 2 );
Password = password2 + password; // two digits on the left of the password
Password = formsauthentication. hashpasswordforstoringinconfigfile (password, "MD5 ");
Return password2 + password;
}
Public String newmima (string password) // encrypt the new password
{
String A = makepassword ();
String P = a + password;
Password = formsauthentication. hashpasswordforstoringinconfigfile (P, "MD5 ");
Return A + password;
}
Public String makepassword ()
{
Int pwdlen = 2; // generate the number of digits of random characters
String pwdchars = "abcdefghijklmnopkrstuvwxyzzbcdefghijklmnopkrstuvwxyz"; // The generated character contains the word
String tmpstr = "";
Int irandnum;
Random RND = new random ();
For (INT I = 0; I <pwdlen; I ++)
{
Irandnum = RND. Next (pwdchars. Length );
Tmpstr + = pwdchars [irandnum];
}
Return tmpstr;
}
</SCRIPT>
<Form runat = "server">
Account: <asp: textbox id = "username" runat = "server"/> <br>
Password: <asp: textbox id = "userpassword" runat = "server"/>
<Asp: button id = "tijiao" text = "Submit" runat = "server" onclick = "yanzheng"/>
<Br>
New Password: <asp: textbox id = "newuserpassword" runat = "server"/>
<Asp: button id = "S" text = "Submit" runat = "server" onclick = "new"/>
</Form>
// Image Scaling
Private void IMG ()
{
System. Drawing. Image oldimg = system. Drawing. image. fromfile (@ "F: \ a.jpg ");
System. Drawing. Image newimg = oldimg. getthumbnailimage (60, 60 * oldimg. Height/oldimg. Width, null, new intptr (0 ));
Newimg. Save (@ "F: \ new.jpg", system. Drawing. imaging. imageformat. JPEG );
Oldimg. Dispose ();
Newimg. Dispose ();
}
// base64 encoding
Public String encodebase64 (string code_type, string code)
{< br> string encode = "";
byte [] bytes = encoding. getencoding (code_type ). getbytes (CODE);
try
{< br> encode = convert. tobase64string (bytes);
}< br> catch
{< br> encode = Code;
}< br> return encode;
}< br> decoding
Public String decodebase64 (string code_type, string code)
{< br> string decode = "";
byte [] bytes = convert. frombase64string (CODE);
try
{< br> decode = encoding. getencoding (code_type ). getstring (bytes);
}< br> catch
{< br> decode = Code;
}< br> return