Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C#] Login form

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
flash harry
Newbie cheater
Reputation: 0

Joined: 19 Jun 2010
Posts: 16

PostPosted: Sun Sep 12, 2010 2:45 pm    Post subject: [C#] Login form Reply with quote

i am trying to make a very simple username/password login screen in C# that checks login details against a simple .txt file hosted on a server.

example:

just a text file on server named login_inf.txt that will contain:

user0:pass0
user1:pass1
user2:pass2
user3:pass3..........etc...

and then just protect it with .htaccess

this is what i have so far:

Code:


using System.Net;
using System.Web;
using System.Security.Cryptography;

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

        private void button1_Click(object sender, EventArgs e)
        {
            string dataFile = "my-website-name . com/login_inf.txt";
            WebClient wc = new WebClient();
            UTF8Encoding utf8 = new UTF8Encoding();
            string requestHtml = "";
            requestHtml = utf8.GetString(wc.DownloadData(dataFile));

            string[] loginData = requestHtml.Split(':');

            if (loginData[1] != txtUser.Text || loginData[0] != md5(txtPass.Text))
            {
                MessageBox.Show("Login Success");
            }
            else
            {
                MessageBox.Show("Login Failed");
            }
        }
    }
}



but im having a problem with it, im not sure why but all it does is check if the file is present on the server and does not check the file for username and password like i want it to.

the problem is even if you enter a wrong username/password it still say login succesful Confused

any ideas why its not checking the text file for username and password?


any help is most appreciated (also i want to keep it simple, and it does not need to be high security).
Back to top
View user's profile Send private message
TROLOLOLOLOLOLOLOLOLOLOLO
Expert Cheater
Reputation: -1

Joined: 27 Dec 2009
Posts: 100

PostPosted: Sun Sep 12, 2010 3:04 pm    Post subject: Reply with quote

Use:

Code:
private string strUser = wc.DownloadString("URL").Split(':')[0], strPass = wc.DownloadString("URL").Split(':')[1];

if (txtUser.Text != strUser || md5(txtPass.Text) != strPass)
MessageBox.Show(null, "Invalid username and or password!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
else
doLogin();


Something of that sort. Not very efficient and easily cracked, but eh.
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sun Sep 12, 2010 10:23 pm    Post subject: Reply with quote

There is a giant security hole here, namely downloading the entire username/password list onto the client's computer to do the check.

You should do the check on your own server, which means you're going to have to write a server application.
Back to top
View user's profile Send private message
flash harry
Newbie cheater
Reputation: 0

Joined: 19 Jun 2010
Posts: 16

PostPosted: Mon Sep 13, 2010 2:58 am    Post subject: Reply with quote

Flyte wrote:
There is a giant security hole here, namely downloading the entire username/password list onto the client's computer to do the check.

You should do the check on your own server, which means you're going to have to write a server application.



yes you are right, ive scrapped this idea for now until i find a better way to do it. (i really wanted to keep it simple and reasonably secure) it doesnt have to be alcatraz tho tbh.


any ideas on how to do this without having to write a server application?
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Mon Sep 13, 2010 3:47 am    Post subject: Reply with quote

If your server supports php it'll be very easy:

The program 'downloads' the following url using the text from the textboxes:
yourserver.com/login.php?user=xxx&pass=xxx

Then if the page contains 'success', the user is logged in.

The php script can be very simple:
(My php is a bit rusty but it should be something like this.)
Code:

<?php
if( $_GET["user"] == "hardcoded_username" && $_GET["pass"] == "hardcoded_password" ){
    echo "success";
}else{
    echo "fail";
}
?>
Back to top
View user's profile Send private message
TROLOLOLOLOLOLOLOLOLOLOLO
Expert Cheater
Reputation: -1

Joined: 27 Dec 2009
Posts: 100

PostPosted: Mon Sep 13, 2010 2:10 pm    Post subject: Reply with quote

tombana wrote:
If your server supports php it'll be very easy:

The program 'downloads' the following url using the text from the textboxes:
yourserver.com/login.php?user=xxx&pass=xxx

Then if the page contains 'success', the user is logged in.

The php script can be very simple:
(My php is a bit rusty but it should be something like this.)
Code:

<?php
if( $_GET["user"] == "hardcoded_username" && $_GET["pass"] == "hardcoded_password" ){
    echo "success";
}else{
    echo "fail";
}
?>



@OP:
If you're going to do that and have a database with users, etc., make sure to secure any string you "get":
Code:
public function secureString($str)
      {
          if (function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc() === 1) {
              $str = stripslashes(htmlentities($str));
          } else {
              $str = htmlentities($str);
          }
          return addcslashes(mysql_real_escape_string(trim($str)), "%_");
      }


Also make all commands in the client check with the server (resend user/pass) and have the client receive its permissions.

For the login you can do something like:
Code:

include_once "./class_with_above_function.php";

$ac = new AboveClass();

if(isset($_GET["user"]) && isset($_GET["pass"])) {
   $user = $ac->secureString($_GET["user"]);
   $pass = $ac->secureString($_GET["pass"]);
   //add MySQL db check stuff
} else {
    print("Invalid parameters and or invalid username/password combination.");
}
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Mon Sep 13, 2010 7:15 pm    Post subject: Reply with quote

If you are still looking to use C# and your server is on Windows (or has access to a .NET emulation such as Mono) just create a web service.

Your application that accesses the service just needs to make calls to the service. Nothing internally done on the client is needed other then making the call to the service and checking if it was successful. (There are some things to keep in mind after a successful login, such as a token or session id per-login and such.)

The service can handle the rest.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Tue Sep 14, 2010 8:12 am    Post subject: Reply with quote

Are you sure you want to let the client handle the auth? If I were you I would proberbly use a service for this.

I would proberbly use asymetric encryption of md5 of login. Then I would most likely send it to some server to verfiy it.

But that's just me Smile

_________________
Intel over amd yes.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
Polynomial
Grandmaster Cheater
Reputation: 5

Joined: 17 Feb 2008
Posts: 524
Location: Inside the Intel CET shadow stack

PostPosted: Tue Sep 14, 2010 8:25 am    Post subject: Reply with quote

If you have the ability to .htaccess, why not just have a text file that says "ok" in a protected directory. User management can then be handled directly by .htaccess and you can tell the application to log in with the credentials given. If it succeeds, you get the file fine. If it doesn't succeed, it's bad credentials. If you can, use SSL for the connection. It'll encrypt the traffic so it can't be sniffed.
_________________
It's not fun unless every exploit mitigation is enabled.
Please do not reply to my posts with LLM-generated slop; I consider it to be an insult to my time.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites