A simple third-party authorized login

Third-party authorized login
Use Visusal Studio2012 to complete a simple third-party authorized login, and interested babies can Kangkang~ The
first step:
open VS and draw a login form with an account, the password box can log in (that is, our The most common login method) insert a picture description here
Insert picture description here

A button button has been newly added to facilitate opening our third-party authorized login page.

Step 2: Complete the code

//登录的控件
private void btn_denglu_Click(object sender, EventArgs e)
{
    
    
    if(txt_Name.Text.Equals("南风知我意")&&txt_password.Text.Equals("0622"))
    {
    
    
        MessageBox.Show("登录成功");
        frmMain main = new frmMain();
        main.user = txt_Name.Text;
        Hide();
        main.ShowDialog();
    }
    else
    {
    
    
        MessageBox.Show("登录失败");
    }
}
//第三方授权登录控件
private void btn_three_Click(object sender, EventArgs e)
{
    
    
    three san = new three();
    //san.Show();
    //模式化
    san.ShowDialog();
    if (san.qqnumber != null)
    {
    
    
        MessageBox.Show("登录成功");
        //登录成功会发生什么
        frmMain main = new frmMain();
        main.user = san.qqnumber;
        Hide();
        main.ShowDialog();
 }

The third step: to open the third-party authorized login button, you need to draw a form and add a webBrowser control (allowing users to browse the web in the form)
Insert picture description here

So which webpage do we want to browse? (Now use the third-party authorized login of QQ space as the web page we want to browse) We need to enter the official website of QQ space from the browser, right-click and check to find the src address in the ifame tag.
Insert picture description here

Step 4: After copying the src address, select the Url in the webBrowser control (specify the place where the web browser control navigates), and paste the src of the QQ space to the Url. Insert picture description here
So what happens after navigation?Insert picture description here

Step 5: At this time, we need to click the Navigated event in the webBrowser control (that is, it will happen after navigation)Insert picture description here

Step 6: After clicking on the Navigated event, we will enter the code section and write the code that will occur after navigation.

 //定义一个 成员变量  用来获取QQ号码
       public string qqnumber;
        //获取导航后的地址
        private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {
    
    
            string url=webBrowser1.Url.ToString();
            string qq = "https://user.qzone.qq.com/";//这个就是QQ空间的网址后面连接的是QQ号码
           // MessageBox.Show(url.Substring(qq.Length));
            if(url.Substring(0,qq.Length).Equals(qq))
            {
    
    
                 //如何获取qq号码
                //总长度-前面的长度
                //https://user.qzone.qq.com/QQ号码—https://user.qzone.qq.com/=QQ号码
                 qqnumber = url.Substring(qq.Length);
                //MessageBox.Show(qqnumber);
                //关闭当前窗口
                 Close();
            }
        }

run:
Insert picture description here

In this way, our simple third-party authorized login is complete!
If you have good suggestions, please leave a message in the comment area!

For more information, please see the interview questions mini program
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_42981560/article/details/113049727