SlideShare a Scribd company logo
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.Text.RegularExpressions;
using System.Windows.Forms;
namespace Login
{
class Login
{
//decalre properties
public string Username { get; set; }
public string Userpassword { get; set; }
//intialise
public Login(string user, string pass)
{
this.Username = user;
this.Userpassword = pass;
}
//validate string
private bool StringValidator(string input)
{
string pattern = "[^a-zA-Z]";
if(Regex.IsMatch(input,pattern))
{
return true;
}
else
{
return false;
}
}
//validate integer
private bool IntegerValidator(string input)
{
string pattern = "[^0-9]";
if(Regex.IsMatch(input,pattern))
{
return true;
}
else
{
return false;
}
}
//clear user inputs
private void ClearTexts(string user, string pass)
{
user = String.Empty;
pass = String.Empty;
}
//method to check if eligible to be logged in
internal bool IsLoggedIn(string user, string pass)
{
//check user name empty
if (string.IsNullOrEmpty(user))
{
MessageBox.Show("Enter the user name!");
return false;
}
//check user name is valid type
else if (StringValidator(user) == true)
{
MessageBox.Show("Enter only text here");
ClearTexts(user,pass);
return false;
}
//check user name is correct
else
{
if (Username != user)
{
MessageBox.Show("User name is incorrect!");
ClearTexts(user,pass);
return false;
}
//check password is empty
else
{
if (string.IsNullOrEmpty(pass))
{
MessageBox.Show("Enter the passowrd!");
return false;
}
//check password is valid
else if (IntegerValidator(pass) == true)
{
MessageBox.Show("Enter only integer here");
return false;
}
//check password is correct
else if(Userpassword!=pass)
{
MessageBox.Show("Password is incorrect");
return false;
}
else
{
return true;
}
}
}
}
}
}
CompleteCsharp
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;
namespace Login
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
//Enter code here for your version of username and userpassword
Login login = new Login("admin", "1234");
private void button1_Click(object sender, EventArgs e)
{
//define local variables from the user inputs
string user = nametxtbox.Text;
string pass = pwdtxtbox.Text;
//check if eligible to be logged in
if(login.IsLoggedIn(user,pass))
{
MessageBox.Show("You are logged in successfully");
}
else
{
//show default login error message
MessageBox.Show("Login Error!");
}
}
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventAr
gs e)
{
//enter your code for forget password case
MessageBox.Show("Under development");
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventAr
gs e)
{
//Enter your code for registration form of your choice
MessageBox.Show("Under development");
}
}
}

More Related Content

DOCX
Week 12 code
PPTX
Sql server ___________session_18(stored procedures)
PPTX
PPS
Procedures/functions of rdbms
PPT
FMDB - SLC-Cocoaheads
TXT
Javascript
PPTX
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
Week 12 code
Sql server ___________session_18(stored procedures)
Procedures/functions of rdbms
FMDB - SLC-Cocoaheads
Javascript
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM

What's hot (19)

ODP
Introduction to triggers
DOC
Pl sql using_xml
PPS
Procedures functions structures in VB.Net
PPTX
Chapter 5 transactions and dcl statements
DOCX
INSERCION DE REGISTROS DESDE VISUAL.NET A UNA BD DE SQL SERVER
PPT
Database Triggers
PPTX
Insert Statement
DOCX
Transaction Management Tool
PPTX
Procedures and triggers in SQL
PPT
7a advanced tsql
DOCX
Functions oracle (pl/sql)
PPT
Oracle Database Trigger
PPT
PHP - Getting good with MySQL part II
PPTX
Stored procedure
PDF
Triggers in plsql
PPTX
Oracle: Cursors
PPTX
Sql Functions And Procedures
PPTX
The secret unit testing tools no one ever told you about
Introduction to triggers
Pl sql using_xml
Procedures functions structures in VB.Net
Chapter 5 transactions and dcl statements
INSERCION DE REGISTROS DESDE VISUAL.NET A UNA BD DE SQL SERVER
Database Triggers
Insert Statement
Transaction Management Tool
Procedures and triggers in SQL
7a advanced tsql
Functions oracle (pl/sql)
Oracle Database Trigger
PHP - Getting good with MySQL part II
Stored procedure
Triggers in plsql
Oracle: Cursors
Sql Functions And Procedures
The secret unit testing tools no one ever told you about
Ad

Similar to Logincode (20)

PPSX
Project: Call Center Management
DOCX
School System C# Code
DOCX
PDF
FNT 2015 PDIS CodeEU - Zanimljiva informatika - 02 Djordje Pavlovic - Live_ch...
PDF
This is a C# project . I am expected to create as this image shows. .pdf
PDF
final project for C#
PPTX
Back-2-Basics: .NET Coding Standards For The Real World (2011)
DOCX
Employee management system report
PPT
Csphtp1 12
PDF
Programming in C#Define an application to include classes for Stud.pdf
PPTX
Windows Form - Lec12 (Workshop on C# Programming: Learn to Build)
DOCX
Dotnet 18
PPT
Library Project Phase 1
PPT
Library Website
PDF
Object Oriented software engineering RECORD.pdf
PDF
Windows Forms For Beginners Part 5
PDF
lab.123456789123456789123456789123456789
 
PDF
C# Program. Create a Windows application that has the functionality .pdf
PDF
Object oriented programming
DOCX
Cis 407 i lab 6 of 7
Project: Call Center Management
School System C# Code
FNT 2015 PDIS CodeEU - Zanimljiva informatika - 02 Djordje Pavlovic - Live_ch...
This is a C# project . I am expected to create as this image shows. .pdf
final project for C#
Back-2-Basics: .NET Coding Standards For The Real World (2011)
Employee management system report
Csphtp1 12
Programming in C#Define an application to include classes for Stud.pdf
Windows Form - Lec12 (Workshop on C# Programming: Learn to Build)
Dotnet 18
Library Project Phase 1
Library Website
Object Oriented software engineering RECORD.pdf
Windows Forms For Beginners Part 5
lab.123456789123456789123456789123456789
 
C# Program. Create a Windows application that has the functionality .pdf
Object oriented programming
Cis 407 i lab 6 of 7
Ad

Recently uploaded (20)

PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
System and Network Administraation Chapter 3
PDF
medical staffing services at VALiNTRY
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Transform Your Business with a Software ERP System
PDF
System and Network Administration Chapter 2
PPTX
CHAPTER 2 - PM Management and IT Context
Navsoft: AI-Powered Business Solutions & Custom Software Development
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Odoo Companies in India – Driving Business Transformation.pdf
2025 Textile ERP Trends: SAP, Odoo & Oracle
How to Migrate SBCGlobal Email to Yahoo Easily
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
How to Choose the Right IT Partner for Your Business in Malaysia
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Upgrade and Innovation Strategies for SAP ERP Customers
wealthsignaloriginal-com-DS-text-... (1).pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Reimagine Home Health with the Power of Agentic AI​
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Operating system designcfffgfgggggggvggggggggg
System and Network Administraation Chapter 3
medical staffing services at VALiNTRY
Design an Analysis of Algorithms II-SECS-1021-03
Transform Your Business with a Software ERP System
System and Network Administration Chapter 2
CHAPTER 2 - PM Management and IT Context

Logincode

  • 1. 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.Text.RegularExpressions; using System.Windows.Forms; namespace Login { class Login { //decalre properties public string Username { get; set; } public string Userpassword { get; set; } //intialise public Login(string user, string pass) { this.Username = user; this.Userpassword = pass; } //validate string private bool StringValidator(string input) { string pattern = "[^a-zA-Z]"; if(Regex.IsMatch(input,pattern)) { return true; } else { return false; } } //validate integer private bool IntegerValidator(string input) { string pattern = "[^0-9]"; if(Regex.IsMatch(input,pattern)) { return true; } else { return false; } } //clear user inputs private void ClearTexts(string user, string pass) { user = String.Empty; pass = String.Empty; } //method to check if eligible to be logged in internal bool IsLoggedIn(string user, string pass) { //check user name empty if (string.IsNullOrEmpty(user)) {
  • 2. MessageBox.Show("Enter the user name!"); return false; } //check user name is valid type else if (StringValidator(user) == true) { MessageBox.Show("Enter only text here"); ClearTexts(user,pass); return false; } //check user name is correct else { if (Username != user) { MessageBox.Show("User name is incorrect!"); ClearTexts(user,pass); return false; } //check password is empty else { if (string.IsNullOrEmpty(pass)) { MessageBox.Show("Enter the passowrd!"); return false; } //check password is valid else if (IntegerValidator(pass) == true) { MessageBox.Show("Enter only integer here"); return false; } //check password is correct else if(Userpassword!=pass) { MessageBox.Show("Password is incorrect"); return false; } else { return true; } } } } } } CompleteCsharp
  • 3. 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; namespace Login { public partial class MainForm : Form { public MainForm() { InitializeComponent(); } //Enter code here for your version of username and userpassword Login login = new Login("admin", "1234"); private void button1_Click(object sender, EventArgs e) { //define local variables from the user inputs string user = nametxtbox.Text; string pass = pwdtxtbox.Text; //check if eligible to be logged in if(login.IsLoggedIn(user,pass)) { MessageBox.Show("You are logged in successfully"); } else { //show default login error message MessageBox.Show("Login Error!"); } } private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventAr gs e) { //enter your code for forget password case MessageBox.Show("Under development"); } private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventAr gs e) { //Enter your code for registration form of your choice MessageBox.Show("Under development"); } } }