Closed Thread
Results 1 to 5 of 5

Thread: Login system

  1. #1
    JakeWindu is offline Newbie
    Join Date
    Nov 2009
    Posts
    21
    Rep Power
    0

    Login system

    I am making a program with a login system, but I cannot get the login part to work.

    This is what I tried:
    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Login_Click(object sender, EventArgs e)
            {
                if (txtuser = "magic" & txtpass = "magic" Form2.ShowDialog;
                else MessageBox.Show("Login failed");
            }
        }
    }
    But it didnt work.

    How can I make a login system that works?

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    so1i's Avatar
    so1i is offline Programming Professional
    Join Date
    Sep 2009
    Location
    Aberystwyth, United Kingdom
    Posts
    309
    Rep Power
    0

    Re: Login system

    Well, for the reason this particular code isn't working, could be to do with a missing bracket.

    Try this.

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Login_Click(object sender, EventArgs e)
            {
                if (txtuser = "magic" & txtpass = "magic") Form2.ShowDialog;
                else MessageBox.Show("Login failed");
            }
        }
    }

  4. #3
    JakeWindu is offline Newbie
    Join Date
    Nov 2009
    Posts
    21
    Rep Power
    0

    Re: Login system

    Cool!
    That got rid of one error

    It still as this error: Error 1 Operator '&' cannot be applied to operands of type 'string' and 'System.Windows.Forms.TextBox' C:\Users\McKinlay\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsForm sApplication1\Form1.cs 21 27 WindowsFormsApplication1

    and this error:Error 2 Only assignment, call, increment, decrement, and new object expressions can be used as a statement C:\Users\McKinlay\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsForm sApplication1\Form1.cs 21 56 WindowsFormsApplication1

  5. #4
    QuackWare is offline Learning Programmer
    Join Date
    Jan 2010
    Posts
    95
    Rep Power
    8

    Re: Login system

    You can't use & to compare two booleans you need to use &&.

    You also need to create an instance of Form2 before you actually call one of its methods. I also added brackets to make things easier.

    And also when your comparing things you need to use double equal signs.

    Your code should look like this.

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Login_Click(object sender, EventArgs e)
            {
                if (txtuser == "magic" && txtpass == "magic")
                { 
                     Form2 f2 = new Form2();
                     f2.ShowDialog();
                }
                else
                {            
                     MessageBox.Show("Login failed");
                }
            }
        }
    Last edited by QuackWare; 01-31-2010 at 02:34 PM.

  6. #5
    JakeWindu is offline Newbie
    Join Date
    Nov 2009
    Posts
    21
    Rep Power
    0

    Re: Login system

    Cool, I figured out how to create a login system!

    Thanks guys!

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. WPF C# login system
    By angelslyrics in forum C# Programming
    Replies: 0
    Last Post: 05-31-2011, 08:22 AM
  2. Session-based Login System Help
    By Hunter100 in forum PHP Development
    Replies: 5
    Last Post: 03-27-2011, 08:08 PM
  3. Beginner Simple Register-Login-Logoff System
    By Jaan in forum PHP Tutorials
    Replies: 76
    Last Post: 01-04-2011, 08:25 PM
  4. PHP login system
    By welton122 in forum PHP Development
    Replies: 14
    Last Post: 09-29-2010, 12:28 PM
  5. need help w/ login system
    By tootsydg2 in forum Java Help
    Replies: 2
    Last Post: 10-20-2008, 06:38 AM

Tags for this Thread

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