This is going to be somewhat a lengthy post, i do hope someone here can help me with this problem that i've already spent a gazillion brain cells on. >.<

I AM a student asking for help as i cannot seem to be making this work with my atrocious programming skills.

I am doing this project as part of my attachment for my diploma.

Meh.


What i've got so far is that i'm done with my UI,
(being very ugly and unprofessional looking, guess i'm going to have to come up with some background designs)

[IMG]http://img.photobucket.com/albums/v95/freakyphua/LoginSample.jpg[/IMG]

This is the code so far,

private void btnA_Click(object sender, EventArgs e)
        {
            if (Pwdsel == 1)
            {
                insertStringPass(btnA.Text, this.Password.SelectionStart);
            }
            else
            {
                insertStringUser(btnA.Text, this.Username.SelectionStart);
            }
        }

        private void btnB_Click_1(object sender, EventArgs e)
        {
            if (Pwdsel == 1)
            {
                insertStringPass(btnB.Text, this.Password.SelectionStart);
            }
            else
            {
                insertStringUser(btnB.Text, this.Username.SelectionStart);
            }
        }

        private void btnC_Click(object sender, EventArgs e)
        {
            if (InputCaps == 0)
            {
                if (Pwdsel == 1)
                {
                    insertStringPass(btnC.Text, this.Password.SelectionStart);
                }
                else
                {
                    insertStringUser(btnC.Text, this.Username.SelectionStart);
                }
            }
        }

        private void btnD_Click(object sender, EventArgs e)
        {
            if (Pwdsel == 1)
            {
                insertStringPass(btnD.Text, this.Password.SelectionStart);
            }
            else
            {
                insertStringUser(btnD.Text, this.Username.SelectionStart);
            }
        }

        private void btnE_Click(object sender, EventArgs e)
        {
            if (Pwdsel == 1)
            {
                insertStringPass(btnE.Text, this.Password.SelectionStart);
            }
            else
            {
                insertStringUser(btnE.Text, this.Username.SelectionStart);
            }
        }

All the buttons are similar, so putting ALL of them here would seem abit silly.

I've also added a button to switch the focus (for the lack of a better word) from the username textbox to the password textbox.

private void UserSubmit_Click(object sender, EventArgs e)
        {
            if (Username.Text.Length < 1)
            {
                MessageBox.Show("Please enter username");
            }
            else
            {
                Username.Enabled = false;
                Password.Enabled = true;
                LoginBtn.Enabled = true;
                UserSubmit.Enabled = false;
                Pwdsel = 1;
            }
        }

But this isn't how i want the program to be, i wanted the users to be able to click on the password textbox and be able to input their passwords using the buttons instead of having to press the submit button to switch the focus. (Emulating input with a keyboard, you just have to click on either textbox to switch the focus to type in your passwords/usernames, right? I'm trying to do the same thing.)

I've tried putting this in, but it just doesn't work!

private void Password_OnClick(object sender, EventArgs e)
        {
            if (Username.Text.Length < 1)
            {
                MessageBox.Show("Please enter username");
            }
            else
            {
                Username.Enabled = false;
                Password.Enabled = true;
                LoginBtn.Enabled = true;
                UserSubmit.Enabled = false;
                this.Password.Focus();
                Pwdsel = 1;
            }
        }

As to why i have to program it with a on screen keyboard, it's because i'm doing this for a smart device running windows CE.

Using the OSK.exe is not a viable option for me :X

Anyhelp is appreciated! Thanks in advance :]

1/. You don't need a new method for every button just call the same method and do somthing like this:

private void btnLetter_Click(object sender, EventArgs e)        
{     
    if (Pwdsel == 1)            
    {               
        insertStringPass((sender as Button).Text, this.Password.SelectionStart); 
    }
    else 
    { 
        insertStringUser((sender as Button).Text, this.Username.SelectionStart);
    }
}

2/. You should be able to use the Click or MouseClick events for the text boxes themselves rather than using the seperate submit button. I am not sure why that is not working for you. I don't think using the focus will work as that will probably be lost when a user clicks a button on your keyboard.

You could force the user to enter a user name and when that is done force them to enter a password.

Haha, that's what i've done, i added a submit button and disabled the password box to force them to enter their username first, this was also a solution to go around the problem with the focus on the password box >.<

i'm going to try the method you showed me.

thanks alot void :D!

private void LoginBtn_Click(object sender, EventArgs e)
        {
            if (Username.Text == "STEE")
            {
                TextWriter tw = new StreamWriter("usernames.txt");

                tw.WriteLine(Username.Text);

                tw.Close();

                if (Password.Text == "12345")
                {
                    TextWriter tpwd = new StreamWriter("passwords.txt");

                    tpwd.WriteLine(Password.Text);

                    tpwd.Close();

                    MessageBox.Show(Username.Text + " successfully logged on");
                }
                else
                {
                    MessageBox.Show("Incorrect Username/Password!");
                }
            }
            else if (Password.Text.Length < 1)
            {
                MessageBox.Show("Please enter password");
            }
            else
            {
                MessageBox.Show("Incorrect Username/Password!");
            }
        }

And also another problem i'm facing is i'm not sure if this is the correct way to store the credentials that the users have entered, is there an alternative method to store them and read? I've gone through MSDN and several forums but i can't seem to make heads or tails of it >.<

To be honest I don't see why you are bothering to store the data there as it will only ever work if the username is STEE and the password is 12345.

If you are going to have different passwords that can be changed you are going to have to store the information on disk. There are two ways to do that, one is a database and the other is in a file. In this case I am assuming a file is the way to go. I think you would be better of with a binary file and you may want to consider encrypting the data depending on how sensative the data is.

Have a look here for tutorials on using files:
http://www.codersource.net/csharp_read_write_binary_files.html
http://www.csharphelp.com/2005/12/simple-text-file-operations-in-c/

To be honest I don't see why you are bothering to store the data there as it will only ever work if the username is STEE and the password is 12345.

If you are going to have different passwords that can be changed you are going to have to store the information on disk. There are two ways to do that, one is a database and the other is in a file. In this case I am assuming a file is the way to go. I think you would be better of with a binary file and you may want to consider encrypting the data depending on how sensative the data is.

Have a look here for tutorials on using files:
http://www.codersource.net/csharp_read_write_binary_files.html
http://www.csharphelp.com/2005/12/simple-text-file-operations-in-c/

I'm hard coding the usernames and passwords in because this is to be used as a demo for now. :/

but minimum requirement is that it has to be able to store and read the usernames and passwords from the textfile(s).

I'll give the links you posted a read, thanks :D!

Ultimately, this is to be integrated into another program, i think the aim of giving me this project is for me to learn, as i am a attachment student (an intern in other words). This product is to be sold as a commercial device, thus i doubt that they will implement something so unprofessional looking :X, afterall, there's still encryption and security and a truck load of stuff to be added on still :/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.