Verification Method for Logon of QQ space and email verification code and solutions for Automatic Logon

Source: Internet
Author: User
Tags microsoft website
Document directory
  •  

<! -- [Endif] -->

There are many SNS communities or SNS-like websites, such as happy, 51, and on-campus websites, however, it is found that most communities do not provide the function of obtaining the friends list of QQ mailbox or QQ space when inviting friends. However, it seems that there are not many QQ articles on the internet, I hope this article will help you.

QqSpace and email login verification methods:

When logging on to the QQ space and mailbox, the password entered by the user will be first encrypted by a piece of JS on the page, and then the encrypted password will be added with the verification code to form a new string, then the new string is encrypted by MD5 (32-bit) to form the final password, this is why we often find that the number of passwords in our password box increases when we submit, and when you submit, the current request adds the set-cookie value returned from the previous verification code to the cookie in the current request header to maintain the consistency between the verification code request and the current request, then, post the new password and user name to the QQ server.

Now, after reading the above QQ verification method, let's take a look at how to use code to log on to the QQ space and mailbox to get the friends and contacts we need.

QqSolution for automatically logging on to the workspace and mailbox to obtain contacts:

To log on to the QQ space and email address, we need to encrypt the user's entered password in JS, but we didn't use a browser when logging on using code. How can we drive JS? Don't worry, there are corresponding methods in Java and. Net to drive JS on the server code side. Here we will focus on the. NET method:

First, Download Windows Script control from the Microsoft website. It is an ActiveX (r) control. After the download and installation are complete, create a C # application project, select the reference node in solution Resource Manager, right-click and choose add reference from the shortcut menu, and the Add reference dialog box is displayed, click Browse to find the directory for installing Windows Script control and select msscript. ocx file. A msscriptcontrol component is added to the reference node. The following are all objects after InterOP.

<! -- [If! VML] --> <! -- [Endif] -->

Scriptcontrol provides simple interfaces for the host script engine that supports ActiveX (TM) scripts. Next, we will explain the attributes and methods of the scriptcontrol converted to the scriptcontrolclass class.

Attribute

Allowui attribute: applies to the user interface elements displayed by scriptcontrol itself or scirpt engine, and can be read and written.

Codeobject attribute: return object, which is used to call public members of a specified module. Read-only.

Error attribute: return the error object, which contains detailed information about the last error. Read-only.

Language attribute: sets or returns the name of the script language in use. Read/write.

Modules attribute: a set of return modules for the scriptcontrol object. Read-only.

Procedures attribute: return the process set defined in the specified module. Read-only.

Sitehwnd property: set or return the hwnd of the window. By executing script code, this window is used to display the dialog box and other user interface elements. Read/write.

State attribute: sets or returns the mode of the scriptcontrol object. Read/write.

Timeout attribute: set or return time (MS). After this time, you can choose to abort the execution of the script code or allow the code to continue. Read/write.

Usesafesubset attribute: sets or returns a Boolean value to indicate whether the host application has confidentiality requirements. If the host application requires security control, usesafesubset is true; otherwise, it is false. Read/write.

Method

Addcode: add the specified code to the module. You can call the addcode method multiple times.

Addobject method: Make the Host Object Model Available to the script engine.

Eval method: calculates the expression and returns the result.

Executestatement method: run the specified statement.

Reset method: discard all script code and objects that have been added to scriptcontrol.

Run method: run the specified process.

Event

Error Event: This event occurs when a running error occurs.

Timeout event: This event occurs when the time specified by the timeout attribute is exceeded and the end is selected in the result dialog box.

Note:

If the allowui attribute is set to false, statements such as the displayed dialog box do not work, such as msgbox statements in VBScript and alert in Javascript. If the executed scripts exceed the milliseconds set in timeout, the dialog box that exceeds the time reminder will not pop up, and vice versa. Resetting the language attribute will clear the code loaded by addcode. For the timeout attribute, when the time-out occurs, scriptcontrol checks the allowui attribute of the object, determine whether to allow display of user interface elements.

To make the control easier to use, use the scriptengine class to encapsulate the following complete code:

Using system;

Using msscriptcontrol;

Using system. text;

Namespace scriptnamespace

{

/// <Summary>

/// Script Type

/// </Summary>

Public Enum scriptlanguage

{

/// <Summary>

/// JScript Language

/// </Summary>

JScript,

/// <Summary>

/// VBSCRIPT script language

/// </Summary>

VBScript,

/// <Summary>

/// Javascript script language

/// </Summary>

Javascript

}

/// <Summary>

/// Script running error proxy

/// </Summary>

Public Delegate void runerrorhandler ();

/// <Summary>

/// Script running timeout proxy

/// </Summary>

Public Delegate void runtimeouthandler ();

/// <Summary>

/// Scriptengine class

/// </Summary>

Public class scriptengine

{

Private scriptcontrol MSC;

// Define a script running error event

Public event runerrorhandler runerror;

// Define the script running timeout event

Public event runtimeouthandler runtimeout;

/// <Summary>

/// Constructor

/// </Summary>

Public scriptengine ()

: This (scriptlanguage. VBScript)

{}

/// <Summary>

/// Constructor

/// </Summary>

/// <Param name = "language"> Script Type </param>

Public scriptengine (scriptlanguage LANGUAGE)

{

This. msc = new scriptcontrolclass ();

This. MSC. usesafesubset = true;

This. MSC. Language = language. tostring ();

(Dscriptcontrolsource_event) This. MSC). Error + = new dscriptcontrolsource_erroreventhandler (scriptengine_error );

(Dscriptcontrolsource_event) This. MSC). Timeout + = new dscriptcontrolsource_timeouteventhandler (scriptengine_timeout );

}

/// <Summary>

/// Run the eval Method

/// </Summary>

/// <Param name = "expression"> Expression </param>

/// <Param name = "codebody"> function body </param>

/// <Returns> returned object </returns>

Public object eval (string expression, string codebody)

{

MSC. addcode (codebody );

Return MSC. eval (expression );

}

/// <Summary>

/// Run the eval Method

/// </Summary>

/// <Param name = "language"> script language </param>

/// <Param name = "expression"> Expression </param>

/// <Param name = "codebody"> function body </param>

/// <Returns> returned object </returns>

Public object eval (scriptlanguage language, string expression, string codebody)

{

If (this. Language! = LANGUAGE)

This. Language = language;

Return eval (expression, codebody );

}

/// <Summary>

/// Run the run Method

/// </Summary>

/// <Param name = "mainfunctionname"> name of the entry function </param>

/// <Param name = "Parameters"> parameter </param>

/// <Param name = "codebody"> function body </param>

/// <Returns> returned object </returns>

Public object run (string mainfunctionname, object [] parameters, string codebody)

{

This. MSC. addcode (codebody );

Return MSC. Run (mainfunctionname, ref parameters );

}

/// <Summary>

/// Run the run Method

/// </Summary>

/// <Param name = "language"> script language </param>

/// <Param name = "mainfunctionname"> name of the entry function </param>

/// <Param name = "Parameters"> parameter </param>

/// <Param name = "codebody"> function body </param>

/// <Returns> returned object </returns>

Public object run (scriptlanguage language, string mainfunctionname, object [] parameters, string codebody)

{

If (this. Language! = LANGUAGE)

This. Language = language;

Return run (mainfunctionname, parameters, codebody );

}

/// <Summary>

/// Discard all script code and objects that have been added to scriptcontrol

/// </Summary>

Public void reset ()

{

This. MSC. Reset ();

}

/// <Summary>

/// Obtain or set the script language

/// </Summary>

Public scriptlanguage Language

{

Get {return (scriptlanguage) enum. parse (typeof (scriptlanguage), this. MSC. Language, false );}

Set {This. MSC. Language = value. tostring ();}

}

/// <Summary>

/// Obtain or set the script execution time, in milliseconds

/// </Summary>

Public int timeout

{

Get {return 0 ;}

}

/// <Summary>

/// Set whether to display the user interface elements

/// </Summary>

Public bool allowui

{

Get {return this. MSC. allowui ;}

Set {This. MSC. allowui = value ;}

}

/// <Summary>

/// Whether the host application has confidentiality requirements

/// </Summary>

Public bool usesafesubset

{

Get {return this. MSC. usesafesubset ;}

Set {This. MSC. usesafesubset = true ;}

}

/// <Summary>

/// Triggered by the runerror event

/// </Summary>

Private void onerror ()

{

If (runerror! = NULL)

Runerror ();

}

/// <Summary>

/// Ontimeout event triggered

/// </Summary>

Private void ontimeout ()

{

If (runtimeout! = NULL)

Runtimeout ();

}

Private void scriptengine_error ()

{

Onerror ();

}

Private void scriptengine_timeout ()

{

Ontimeout ();

}

}

}

Find. net-driven js method, we also need to find the JS file that QQ uses to encrypt. For specific JS files, you can download them on the QQ login page, if you do not know which JS is available, you can find it by capturing packets, so we will not go into details here. Next we can use msscriptcontrol to drive js to obtain the first encrypted password. The method is as follows:

/// <Summary>

/// Obtain the first encrypted password

/// </Summary>

/// <Param name = "jsfilepath"> JS file </param>

/// <Param name = "funcname"> name of the encryption method </param>

/// <Param name = "paramers"> parameters to be passed in the encryption method (one is the password and the other is the token obtained on the page) </param>

/// <Returns> encrypted password </returns>

Private object GetPassword (string jsfilepath, string funcname, Params object [] paramers)

{

Streamreader reader = new streamreader (jsfilepath );

String sscript = reader. readtoend ();

Scriptengine Se = new scriptengine (scriptlanguage. Javascript );

Object OBJ = Se. Run (funcname, paramers, sscript );

Return OBJ;

}

Through the above function, we can encrypt the password for the first time. Next, we need to obtain the verification code.

We can use the httpwebrequest class to get the request address: Response.

Now we can convert the obtained verification code into a stream or other methods for output by different platforms. We find that the image generated by the Verification code of the QQ space and mailbox is not too complex, therefore, you can consider using image recognition to automatically obtain the characters corresponding to the image (there are many third-party verification code recognition software). Of course, for the sake of success rate, it is best to let the user manually input.

Now that we have the verification code, we can add the verification code character with the password we just added to form a new string and then encrypt it with MD5.

String Pwd = formsauthentication. hashpasswordforstoringinconfigfile (this. password, "MD5"). tolower ()

Form the final password we need.

Finally, we can post the user name and password entered by the user to the corresponding QQ address, so that we can successfully log on to the QQ space or mailbox. After successful login, you can certainly get contacts and friends.

Well, this article is written, hoping to be useful to everyone. ^ Brave Chen

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.