C# login & Registrations form with MySQL and MD5 Password

C# (CSharp) tutorial pemula : belajar c# cara membuat aplikasi login dan register user sederhana dengan menggunakan database MySQL dan MD5 password.

C# untuk pemula - Bagaimana cara membuat aplikasi login dan registrer user dengan hak akses yang berbeda - beda menggunakan database MySQL dan password dalam format MD5? tutorial C# kali ini kami akan mencoba menjelaskan tentang pembuat aplikasi windows form sederhana bahasa pemrogramman C#, seperti yang sudah pernah kami bahas sebelumnya tentang pembuatan form login dan register juga tapi dengan menggunakan bahasa programm vb.net.

Read : How to Create Login & Register form Using MD5 Password ?
How to make a database (MySQL) ?
How to crate Connections in C# ?

Membuat Project Login dan Register C#

Langsung saja kita akan membuat project baru dengan visual studio 2015, dan sebelumnya saya pestikan kamu sudah harus membuat sebuah database MySQL, kamu juga bisa mendownload source code dan contoh database yang digunakan dalam tutorial ini nantinya.
Buatlah project baru dan beri nama "RegisterLogin-c", atau bisa kamu sesuaikan sesuai kebutuhan aja. ikuti tutorial selanjutnya di bawah ini.

Form Login dan Register

pada Form1.cs ubah menjadi FormLogin.cs, disini kita akan membuat window tampilan untuk user login. desainlah tampilan halaman login seperti gambar berikut :

Login Form C#

Selanjutnya buatlah form baru dengan nama FormRegistrations.cs dan desain tampilan FormRegistration.cs seperti gambar dibawah ini :

Registration Form

Kira - kira tampilan login form dan registration form seperti tampilan diatas, kamu bisa saja menyesuaikan dengan kebutuhan kamu.

Source Code Form Login C Sharp

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.Odbc;

namespace LoginRegister_C {
    public partial class LoginForm : Form {

        // before you must have a database (MySQL database)
        // and we will create a connection using ODBC class
        OdbcConnection connection = new OdbcConnection("DSN=java_db;MultipleActiveResultSets=True");
        public LoginForm() {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e) {
            connection.Open(); //open our connection
            OdbcDataReader dr; // declaration data reader
            OdbcCommand cmd; // declaration command
            // syntax for read all data from users tables
            string sql = "SELECT * FROM users WHERE name='"+ textBox1.Text +"' and password=MD5('"+ textBox2.Text +"')";
            cmd = new OdbcCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = sql;
            cmd.Connection = connection;
            dr = cmd.ExecuteReader();
            if (dr.HasRows) { // if data reader not null

                while(dr.Read()) {
                    if(dr["level"].ToString() == "1") {
                        // if level is 1, its just for our Administrations
                        // so just show any form for administrator
                        MessageBox.Show("Wellcome Administrator using access level 1", "Information");
                    } else if(dr["level"].ToString() == "2") {
                        // if level is 2, its just for user
                        // so just show any form for user
                        MessageBox.Show("Wellcome User using access level 2", "Information");
                    } else if(dr["level"].ToString() == "3") {
                        // if level is 3, its just for other
                        // so just show any form for other
                        MessageBox.Show("Wellcome Other using access level 3", "Information");
                    } // you can add more user access level here
                    else {
                        // show warning if not registered with any level
                        MessageBox.Show("Not registered with any level access", "Warning");
                    }
                }
            } else {
                // show message if wrong username or password
                MessageBox.Show("Username or password wrong", "Waning");
            }
            connection.Close(); // close our connections
            cmd.Dispose();
        }
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
            FormRegistrations reg = new FormRegistrations();
            reg.Show(); // show our ne form registrations
        }
        private void button2_Click(object sender, EventArgs e) {
            this.Close(); // close form
        }
    }
}

Source Code Form Registrations C Sharp

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.Odbc; // import namespace of ODBC
namespace LoginRegister_C {
    public partial class FormRegistrations : Form {
        // same with login form, create connection using ODBC class with MySQL database
        OdbcConnection connection = new OdbcConnection("DSN=java_db;MultipleActiveResultSets=True");
        public FormRegistrations() {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e) {
            connection.Open(); // open our connection
            string TypeUser; // declaration type user to string
            int level = Convert.ToInt32(0);
            TypeUser = comboBox1.Text;
            if(TypeUser == "administrator") {
                // if type user is administrator, so level is 1
                level = 1;
            } else if(TypeUser == "user") {
                level = 2; // if type user is "user", so level is 2
            } else if(TypeUser == "other") {
                level = 2; // if other, level is 3
            } else {
                // show message if level user is not selected when registering
                MessageBox.Show("Please select any level user", "Warning");
            }
            OdbcDataReader dr; // declaration our data reader
            OdbcCommand cmd; //declaration our command
            // declaration our syntax to save new user into users tables MySQL database
            // the password will be automatic convert into MD5 password
            string sql = "INSERT INTO users(name,password,level) VALUES('"+ textBox1.Text +"',MD5('"+ textBox2.Text +"'),'"+ level +"')";
            cmd = new OdbcCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = sql;
            cmd.Connection = connection;
            dr = cmd.ExecuteReader();
            // show message when success registrations
            MessageBox.Show("Registrations Success !", "Information");
            connection.Close(); // close our connection
            cmd.Dispose();
        }
        private void FormRegistrations_Load(object sender, EventArgs e) {
            comboBox1.Text = "administrator";
        }
        private void button2_Click(object sender, EventArgs e) {
            this.Close();
        }
    }
}

Jangan lupa menambahkan item pada combobox1 pada form Registration, item yang ditambahkan : administrator, user, other.

Jika semuanya sudah selesai coba jalankan aplikasi sederhana kamu, harus nya akan berjalan baik. jika masih bingung dengan tutorial diatas, silahkan lihat video tutorial berikut ini :

Video tutorial C# login & Registrations form with MySQL and MD5 Password



Download Aplikasi C# login & Registrations form
Download Database Project

COMMENTS

Next Recomended


Feel free to code it up and send us a pull request.

Hi everyone, let's me know how much this lesson can help your work. Please Subscribe and Follow Our Social Media 'kodeajaib[dot]com' to get Latest tutorials and will be send to your email everyday for free!, Just hit a comment if you have confused. Nice to meet you and Happy coding :) all ^^



Follow by E-Mail


Name

ADO.NET,3,Ajax,6,Android,9,AngularJS,4,ASP.NET,4,Blogger Tutorials,7,Bootstrap,7,C++,1,Codeigniter,2,Cplusplus,6,Crystal Report,6,CSharp,25,Ebook Java,2,FlyExam,1,FSharp,3,Game Development,2,Java,35,JDBC,2,Laravel,84,Lumen,2,MariaDB,2,Ms Access,3,MySQL,31,ODBC,6,OleDB,1,PHP,14,PHP Framework,5,PHP MYSQLI,9,PHP OOP,5,Python,8,Python 3,4,SQL Server,4,SQLite,4,Uncategorized,5,Vb 6,2,Vb.Net,89,Video,48,Vue Js,4,WPF,2,Yii,3,
ltr
item
KODE AJAIB: C# login & Registrations form with MySQL and MD5 Password
C# login & Registrations form with MySQL and MD5 Password
C# (CSharp) tutorial pemula : belajar c# cara membuat aplikasi login dan register user sederhana dengan menggunakan database MySQL dan MD5 password.
https://3.bp.blogspot.com/-MBBi_njstCc/V0n4pguWDnI/AAAAAAAAByo/6XSfVPS09wosNHYhh_keD4-A8ZNqnf5zwCLcB/s320/login-form-c-sharp.jpg
https://3.bp.blogspot.com/-MBBi_njstCc/V0n4pguWDnI/AAAAAAAAByo/6XSfVPS09wosNHYhh_keD4-A8ZNqnf5zwCLcB/s72-c/login-form-c-sharp.jpg
KODE AJAIB
https://www.kodeajaib.com/2016/05/c-login-registrations-form-with-mysql.html
https://www.kodeajaib.com/
https://www.kodeajaib.com/
https://www.kodeajaib.com/2016/05/c-login-registrations-form-with-mysql.html
true
3214704946184383982
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy