Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15
  1. #11
    Junior Member
    Join Date
    Dec 2009
    Posts
    23

    Re: Login System, combined with PHP - C# - MySQL

    Quote Originally Posted by FreckleS View Post
    Not right now, I have 10 stitches in my elbow and I am going on holidays.
    Alrights, Than ill wait in patience =) Have nice holidays ^^

  2. #12
    Junior Member
    Join Date
    Aug 2007
    Location
    Czech Republic
    Posts
    8

    Re: Login System, combined with PHP - C# - MySQL

    Hi! Its a pitty u havent understand my explain, but how freckles said u want to seend request to web and get response and there i have problem too I am sending request by webbrowser.navigate like i posted before but i want to know how to send request that i will be able to get some response (i.e.: wich products he have bought and if the pass and user was correct etc) [this points to u freckles coz u looks that u know how xD] I need help now too xD....

    Cheerzzz
    --
    hYpnotiZe

  3. #13
    VIP
    Join Date
    Apr 2006
    Location
    AL, USA
    Posts
    184

    Re: Login System, combined with PHP - C# - MySQL

    You do not want to use a web browser control to try and programmatically retrieve and submit data.
    That is just not what that particular control is for. (Stupid control tbh)

    Here is a small example. This is by no means secure or crack proof, but at least something to get you started.

    Make a new c# winforms project with 2 textboxes and a button.
    The textboxes should be named "txtUser" and "txtPass".
    The button should be named "btnLogin"
    Of course, you could name them whatever you want, but that's just what I referred to them as in the pasted code.
    Delete anything in FORM1.CS (under code view):


    Form1.cs
    PHP Code:
    using System.Security.Cryptography;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Drawing;
    using System.Data;
    using System.Linq;
    using System.Text;
    using System.Net;
    using System.IO;
    using System;




    namespace 
    WebAuth
    {
        public 
    partial class Form1 Form
        
    {
            public 
    Form1()
            {
                
    InitializeComponent();
            }


            private 
    string GetMD5(string StrToHash)
            {
                
    byte[] hash MD5CryptoServiceProvider.Create().ComputeHash(Encoding.ASCII.GetBytes(StrToHash));
                
    StringBuilder str = new StringBuilder();
                foreach(
    byte b in hash)
                {
                    
    str.Append(b.ToString("x2"));
                }
                return 
    str.ToString();
            }

            private 
    void doLogin()
            {
                
    ASCIIEncoding encoding = new ASCIIEncoding();
                
    string DataToPost "user=" txtUser.Text "&pass=" GetMD5(txtPass.Text);
                
    byte[] data encoding.GetBytes(DataToPost);
                
    StringBuilder sb = new StringBuilder();

                
    //Setup a web request. This is our programmatic connection to the website.
                
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://skynet-nix1/testing/auth.php");
                
    //Tell it we are going to post some data.
                
    request.Method "POST";
                
    //From a FORM.
                
    request.ContentType "application/x-www-form-urlencoded";
                
    //And tell it how much data to expect (This can be used to upload data.....)
                
    request.ContentLength data.Length;
                
    //Get a stream for our connection so we can write.
                
    Stream sendStream request.GetRequestStream();
                
    //Send our data out.
                
    sendStream.Write(data0data.Length);
                
    sendStream.Close();
                
                
                
    // Read buffer.
                
    byte[] bRead = new byte[8192];

                
    //See what got returned.
                
    HttpWebResponse response = (HttpWebResponserequest.GetResponse();

                
    //Read stream.
                
    Stream resStream response.GetResponseStream();

                
    //Used for data operations bewlow.
                
    string tempString null;
                
    int count 0;

                do
                {
                    
    //Fill our buffer.
                    
    count resStream.Read(bRead0bRead.Length);

                    
    //Check to see if we got a response.
                    
    if (count != 0)
                    {
                        
    //We dont need byte data.
                        
    tempString Encoding.ASCII.GetString(bRead0count);
                        
    //Add current ascii to our response string.
                        
    sb.Append(tempString);
                    }
                }
                while (
    count 0); // Loop until we are out of data.

                
                
    if (sb.ToString() == "Hello")
                    
    MessageBox.Show("Login Successful");
                else
                    
    MessageBox.Show("Login Failed");
            }

            private 
    void btnLogin_Click(object senderEventArgs e)
            {
                
    doLogin();
            }
        }

    Auth.php looks like:
    PHP Code:
    <?php

        
    require 'dbconnect.php';

        
    $myusername=$_POST['user'];
        
    $mypassword=$_POST['pass'];

        
    $myusername stripslashes($myusername);
        
    $mypassword stripslashes($mypassword);
        
    $myusername mysql_real_escape_string($myusername);
        
    $mypassword mysql_real_escape_string($mypassword);

        
    $sql="SELECT * FROM test_users WHERE username='$myusername' and password='$mypassword'";
        
        
    $result=mysql_query($sql);
        
    $count=mysql_num_rows($result);
            
        if(
    $count==1)
            echo 
    "Hello";
        else 
            echo 
    "Invalid login."
    ?>
    And dbconnect.php looks like:
    PHP Code:
    <?php
    $dbServer 
    "skynet-nix1";
    $dbName "SKY_TEST";
    $dbUser "testuser";
    $dbPass "testpass";

    $con mysql_connect($dbServer$dbUser$dbPass) or die(mysql_error());
    mysql_select_db($dbName) or die(mysql_error());
    ?>

    To extend this and secure it, you may want to consider SSL, using a replace algorithm on the md5 hashing, challenge strings, a hwid hash, etc etc.

    Hope this helps either way.

  4. #14
    VIP FreckleS's Avatar
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    2,121

    Re: Login System, combined with PHP - C# - MySQL

    back guys, if you still need any help let me know, you shouldn't cause skyline covered it great!
    "The pain you feel today, will be the strength you feel tomorrow"

  5. #15
    Junior Member scuter's Avatar
    Join Date
    May 2013
    Posts
    1

    Re: Login System, combined with PHP - C# - MySQL

    I know that this thread is very old, but I need support for that. I made everything like in the tutorial above but it instantly says "Access Denied", even with the correct userdata :|

Page 2 of 2 FirstFirst 12

Similar Threads

  1. [PHP]Snippet - MYSQL
    By sil#s in forum Html, Php, Xml, Css, ...
    Replies: 4
    Last Post: July 8th, 2010, 18:31
  2. Replies: 2
    Last Post: June 7th, 2010, 13:45
  3. [TUT]C# SIMPLE login system
    By nowolu in forum Tutorials
    Replies: 0
    Last Post: May 2nd, 2010, 17:41
  4. Offering help on Mysql, php and css
    By michael1987 in forum Html, Php, Xml, Css, ...
    Replies: 1
    Last Post: January 27th, 2009, 18:40
  5. Log in at website (MySQL?)
    By Square in forum Html, Php, Xml, Css, ...
    Replies: 6
    Last Post: December 8th, 2008, 17:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •