Programming for Everybody: login form
Showing posts with label login form. Show all posts
Showing posts with label login form. Show all posts

C# Login Form with Multiple Users & Permissions with SQL Server | C# Tutorial With Source code

 Source Code:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using System.Data.SqlClient;

namespace login_form

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=database6;Integrated Security=True");

        public static string user_v;

        private void checkBox1_CheckedChanged(object sender, EventArgs e)

        {

            if(checkBox1.Checked)

            {

                textBox1.UseSystemPasswordChar = false;

            }

            else

            {

                textBox1.UseSystemPasswordChar = true;

            }

        }


        private void button2_Click(object sender, EventArgs e)

        {

            Application.Exit();

        }


        private void button1_Click(object sender, EventArgs e)

        {

            conn.Open();

            SqlCommand cmd = new SqlCommand("Select username,password From users Where username='Admin' And password=@pass", conn);

            cmd.Parameters.AddWithValue("pass", textBox1.Text);

            SqlDataReader myreader;

            myreader = cmd.ExecuteReader();

            if(myreader.Read())

            {

                int resultcomp = String.Compare(textBox1.Text, myreader.GetValue(1).ToString());

                if(resultcomp==0)

                {

                    user_v = myreader["username"].ToString();

                    Form2 gg = new Form2();

                    gg.Show();

                    this.Hide();

                    conn.Close();

                }

                else

                {

                    conn.Close();

                    MessageBox.Show("Error username or password");

                }

            }

            else

            {

                conn.Close();

                MessageBox.Show("Error username or password");

            }

        }


        private void checkBox2_CheckedChanged(object sender, EventArgs e)

        {

            if (checkBox2.Checked)

            {

                textBox2.UseSystemPasswordChar = false;

            }

            else

            {

                textBox2.UseSystemPasswordChar = true;

            }

        }


        private void Form1_Load(object sender, EventArgs e)

        {

            fill_combo();

        }

        private void fill_combo()

        {

            SqlCommand cmd2 = new SqlCommand("Select id,username From users Where username<>'Admin'", conn);

            SqlDataAdapter da = new SqlDataAdapter(cmd2);

            DataTable dt = new DataTable();

            da.Fill(dt);

            comboBox1.DataSource = dt;

            comboBox1.DisplayMember = "username";

            comboBox1.ValueMember = "id";

            comboBox1.SelectedIndex = -1;

            comboBox1.Text = "Select user";

        }


        private void button3_Click(object sender, EventArgs e)

        {

            Application.Exit();

        }


        private void button4_Click(object sender, EventArgs e)

        {

            if (comboBox1.SelectedValue==null)

            {

                MessageBox.Show("Please Select user");

            }

            else

            {

            conn.Open();

            SqlCommand cmd = new SqlCommand("Select * From users Where id=@id And password=@pass", conn);

                cmd.Parameters.AddWithValue("id", comboBox1.SelectedValue);

                cmd.Parameters.AddWithValue("pass", textBox2.Text);

            SqlDataReader myreader;

            myreader = cmd.ExecuteReader();

            if (myreader.Read())

            {

                int resultcomp = String.Compare(textBox2.Text, myreader.GetValue(2).ToString());

                if (resultcomp == 0)

                {

                    user_v = myreader["username"].ToString();

                        string add_v, update_v, delete_v;

                        add_v = Convert.ToString(myreader["add_data"].ToString());

                        update_v = Convert.ToString(myreader["update_data"].ToString());

                        delete_v = Convert.ToString(myreader["delete_data"].ToString());

                        Form2 gg = new Form2();


                        if (add_v == "True")

                            gg.add_btn.Visible = true;

                        else

                            gg.add_btn.Visible = false;


                        if (update_v == "True")

                            gg.update_btn.Visible = true;

                        else

                            gg.update_btn.Visible = false;


                        if (delete_v == "True")

                            gg.delete_btn.Visible = true;

                        else

                            gg.delete_btn.Visible = false;




                        gg.Show();

                    this.Hide();

                    conn.Close();

                }

                else

                {

                    conn.Close();

                    MessageBox.Show("Error username or password");

                }

            }

            else

            {

                conn.Close();

                MessageBox.Show("Error username or password");

            }

        }

    }

    }

}



Excel VBA tutorial for beginners- How to create login form in Microsoft Excel VBA with source code



In this video, we'll learn how to create a login form in Microsoft Excel using VBA. We'll show you how to create a user login form with a show and hide password textbox. This tutorial is useful if you need to create a login form for your website or application. If you're a Microsoft Excel user, then this video is for you! In this video, we'll show you how to create a user login form using VBA. We'll show you how to create a user login form with a show and hide password textbox. This tutorial is useful if you need to create a login form for your website or application. So make sure to watch the video and learn how to create a login form with 
Subscribe to my channel to find everyday new information in programming and Computerr Science Subscribe to @programmingforeverybody
https://www.youtube.com/@programmingforeverybody/?sub_confirmation=1
Source Code:
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
passtxt.PasswordChar = ""
Else
passtxt.PasswordChar = "*"
End If
End Sub

Private Sub CommandButton1_Click()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Sheet2")
Dim i As Integer
For i = 1 To ws.UsedRange.Rows.Count
If usertxt.Value = ws.Cells(i, 1).Value And passtxt.Value = ws.Cells(i, 2).Value Then
UserForm1.lbl_user.Caption = Me.usertxt.Value
Unload Me
UserForm1.Show
Exit Sub
End If
Next
MsgBox ("Error username or password")
End Sub

How to create login form in Microsoft Access VBA 2023

 


In this video, we're going to show you how to create a login form in Microsoft Access 2016. This is a useful skill if you need to create a login form for a database or if you're developing a custom application. If you're looking to learn how to create a login form in Microsoft Access 2023, then this video is for you! We'll walk you through the steps necessary to create a login form in Access 2016, and provide some helpful tips along the way. Watch and learn! Subscribe to @programmingforeverybody https://www.youtube.com/@programmingforeverybody/?sub_confirmation=1


How to create login form with multi users and permissions in VB.net using Sql database[with Source code]




 Imports System.Data.SqlClient

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim conn As New SqlConnection("Data source=.;initial catalog=login3;integrated security=true")

        If conn.State = ConnectionState.Closed Then

            conn.Open()

        End If

        Dim cmd As New SqlCommand("Select * from Admin where username='admin' and password=@password", conn)

        cmd.Parameters.AddWithValue("password", TextBox1.Text)

        Dim myreader As SqlDataReader = cmd.ExecuteReader

        If (myreader.Read()) Then

            username_v = myreader("username")

            Form2.Show()

            Me.Hide()

        Else

            MsgBox("Error Password")

        End If

    End Sub


    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        Me.Close()

    End Sub


    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click

        Dim conn As New SqlConnection("Data source=.;initial catalog=login3;integrated security=true")

        If conn.State = ConnectionState.Closed Then

            conn.Open()

        End If

        Dim cmd As New SqlCommand("Select * from users where username=@username and password=@password", conn)

        cmd.Parameters.AddWithValue("username", TextBox3.Text)

        cmd.Parameters.AddWithValue("password", TextBox2.Text)

        Dim myreader As SqlDataReader = cmd.ExecuteReader

        If (myreader.Read()) Then

            username_v = myreader("username")

            If Not myreader.IsDBNull(myreader.GetOrdinal("insert")) Then

                CheckBox1.Checked = myreader("insert")

            End If

            If Not myreader.IsDBNull(myreader.GetOrdinal("update")) Then

                CheckBox2.Checked = myreader("update")

            End If

            If Not myreader.IsDBNull(myreader.GetOrdinal("delete")) Then

                CheckBox3.Checked = myreader("delete")

            End If

            If CheckBox1.Checked = False Then

                Form2.Button1.Visible = False

            End If

            If CheckBox2.Checked = False Then

                Form2.Button2.Visible = False

            End If

            If CheckBox3.Checked = False Then

                Form2.Button3.Visible = False

            End If


            Form2.Show()

                Me.Hide()

            Else

                MsgBox("Error Password")

        End If

    End Sub


    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

        Me.Close()

    End Sub

End Class

ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ

Public Class Form2

    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Label1.Text = "Welcome, " & username_v

    End Sub

End Class

ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ

Module Module1

    Public username_v As String

End Module

Programming with C # tutorial: Login Form in C # with SQL Server

 





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;
using System.Data.SqlClient;


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

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("Data source=.; initial catalog=users;integrated security=true");

            SqlCommand cmd = new SqlCommand("select * from login1 where user1=@user1 and pass1=@pass1", conn);

            cmd.Parameters.Add("@user1", SqlDbType.VarChar).Value = textBox1.Text;

            cmd.Parameters.Add("@pass1", SqlDbType.VarChar).Value = textBox2.Text;


            SqlDataAdapter adapter1 = new SqlDataAdapter(cmd);

            DataTable table = new DataTable();

            adapter1.Fill(table);

            if (table.Rows.Count == 1)
            {

                Form2 gg = new Form2();

                gg.Show();

                this.Hide();

            }
            else
            {
                MessageBox.Show("Error username or password");


            }



        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();

        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {

            if (checkBox1.Checked == true)
            {
                textBox2.UseSystemPasswordChar = false;
            }
            else
            {

                textBox2.UseSystemPasswordChar = true;
            }



        }

       
    }

    }

C# : Create Login form in C# step by step [ with source 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;
using System.Data.SqlClient;


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

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("Data source=.; initial catalog=users;integrated security=true");

            SqlCommand cmd = new SqlCommand("select * from login1 where user1=@user1 and pass1=@pass1", conn);

            cmd.Parameters.Add("@user1", SqlDbType.VarChar).Value = textBox1.Text;

            cmd.Parameters.Add("@pass1", SqlDbType.VarChar).Value = textBox2.Text;


            SqlDataAdapter adapter1 = new SqlDataAdapter(cmd);

            DataTable table = new DataTable();

            adapter1.Fill(table);

            if (table.Rows.Count == 1)
            {

                Form2 gg = new Form2();

                gg.Show();

                this.Hide();

            }
            else
            {
                MessageBox.Show("Error username or password");


            }



        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();

        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {

            if (checkBox1.Checked == true)
            {
                textBox2.UseSystemPasswordChar = false;
            }
            else
            {

                textBox2.UseSystemPasswordChar = true;
            }



        }
    }

    }

Login form access database vb.net

  Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\gamal\Pictures\aa.mdb")
        Dim cmd As New OleDbCommand("select* from login1 where user1=@userl and pass1=@pass1", conn)
        cmd.Parameters.Add("@userl", OleDbType.VarChar).Value = TextBox1.Text
        cmd.Parameters.Add("@pass1", OleDbType.VarChar).Value = TextBox2.Text
        Dim adapter1 As New OleDbDataAdapter(cmd)
        Dim table As New DataTable
        adapter1.Fill(table)
        If table.Rows.Count <= 0 Then
            MsgBox("Error username or password")
        Else
            MsgBox("login successfully")
        End If