0% found this document useful (0 votes)
53 views5 pages

Using Using Using Using Using Using Using Using Using Using Public Partial Class New New New New Double Int Int Int Char

This document contains code for a login page that implements encryption and decryption of user credentials using RSA encryption. It defines variables and methods for connecting to a database, encrypting and decrypting text using RSA with predefined encryption and decryption keys, and validating login credentials in the database. The code takes user input, encrypts it using RSA, and checks the encrypted value against the database to authenticate the user.

Uploaded by

daya telang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views5 pages

Using Using Using Using Using Using Using Using Using Using Public Partial Class New New New New Double Int Int Int Char

This document contains code for a login page that implements encryption and decryption of user credentials using RSA encryption. It defines variables and methods for connecting to a database, encrypting and decrypting text using RSA with predefined encryption and decryption keys, and validating login credentials in the database. The code takes user input, encrypts it using RSA, and checks the encrypted value against the database to authenticate the user.

Uploaded by

daya telang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

using System;

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Cryptography;
using Microsoft.VisualBasic;
using System.Data.SqlClient;
using System.Data;

public partial class Login : System.Web.UI.Page


{
SqlCommand cmd = new SqlCommand();
SqlConnection con = new SqlConnection();
SqlDataAdapter sda = new SqlDataAdapter();
DataSet ds = new DataSet();
double v1;
int p = 7, q = 17, inx, i, pos, asciivlue;
int[] eKey = { 5, 11, 13, 19, 23, 29, 31, 37 };
int[] dKey = { 77, 35, 37, 91, 71, 53, 31, 13 };
String ip, encr = "";
char[] charArr =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
String strrandom = "";
Random objran = new Random();
char x;
String TexttoEncrypt;
double asciivlue1;
protected void Page_Load(object sender, EventArgs e)
{

con.ConnectionString = "Data
Source=.\\SQLEXPRESS;AttachDbFilename=F:\\WebSite11\\App_Data\\Database.mdf;Integrated
Security=True;User Instance=True";
con.Open();
}
protected void btnSubmit_Click(object sender, EventArgs e)
{

//Response.Redirect("WelcomePage.aspx");
//salting
ip = TextBox2.Text;
for (int i = 1; i <= 12; i++)
{
pos = objran.Next(1, charArr.Length);
if (strrandom.Contains(charArr.GetValue(pos).ToString()))
{
i--;
}
else
{
strrandom += charArr.GetValue(pos);
}
}
TextBox2.Text = ip + strrandom;
//encoding
ip = TextBox2.Text;
charArr = ip.ToCharArray();
for (int i = 0; i < ip.Length; i++)
{
asciivlue = (int)charArr[i];
x = (char)(asciivlue + 6);
encr += x;
}
TextBox2.Text = encr;
//rsa
TexttoEncrypt = encr;
encr = "";
TexttoEncrypt = TexttoEncrypt.Substring(0, TexttoEncrypt.Length - 12);
charArr = TexttoEncrypt.ToCharArray();
inx = 5; //objran.Next(0, 7);
//TextBox3.Text = TexttoEncrypt;
for (int i = 0; i < TexttoEncrypt.Length; i++)
{
asciivlue = getIntValue(charArr[i]);
// TextBox3.Text += asciivlue1;
//(Math.Pow(asciivlue, eKey(inx)) Mod (p * q)) Mod 26
v1 = pwr(asciivlue, eKey[inx]);
//v1 = Math.Floor(v1);
// TextBox3.Text += v1 + ",";
x = getChrValue((int)((pwr(asciivlue, eKey[inx]) % (p * q)) % 26));
encr += x;
}
// TextBox2.Text = encr;
// TextBox1.Text = encr;
// TextBox2.Text = "";
//database
cmd.CommandText = "Select * from Table1 where UID ='" + TextBox1.Text + "' and
Password ='" + encr + "'";
cmd.Connection = con;
sda.SelectCommand = cmd;
sda.Fill(ds, "Table1");
if (ds.Tables[0].Rows.Count > 0)
{
Label1.Text = "Login Successfull";
}
else
{
Label1.Text = "Login fail";
}

}
public double pwr(int no, int p)
{
double power = 1;
for (int i = 1; i <= p; i++)
{
power *= no;
}
return (power);
}
public int getIntValue(char ch)
{
switch (ch)
{

case 'a':
return (1);
case 'b':
return (2);
case 'c':
return (3);
case 'd':
return (4);
case 'e':
return (5);
case 'f':
return (6);
case 'g':
return (7);
case 'h':
return (8);
case 'i':
return (9);
case 'j':
return (10);
case 'k':
return (11);
case 'l':
return (12);
case 'm':
return (13);
case 'n':
return (14);
case 'o':
return (15);
case 'p':
return (16);
case 'q':
return (17);
case 'r':
return (18);
case 's':
return (19);
case 't':
return (20);
case 'u':
return (21);
case 'v':
return (22);
case 'w':
return (23);
case 'x':
return (24);
case 'y':
return (25);
case 'z':
return (26);
default:
return (0);
}
}
public char getChrValue(int ch)
{
// int ch1 = (int)ch;
switch (ch)
{
case 1:
return ('a');
case 2:
return ('b');
case 3:
return ('c');
case 4:
return ('d');
case 5:
return ('e');
case 6:
return ('f');
case 7:
return ('g');
case 8:
return ('h');
case 9:
return ('i');
case 10:
return ('j');
case 11:
return ('k');
case 12:
return ('l');
case 13:
return ('m');
case 14:
return ('n');
case 15:
return ('o');
case 16:
return ('p');
case 17:
return ('q');
case 18:
return ('r');
case 19:
return ('s');
case 20:
return ('t');
case 21:
return ('u');
case 22:
return ('v');
case 23:
return ('w');
case 24:
return ('x');
case 25:
return ('y');
case 26:
return ('z');

default:
return ('z');
}
}
protected void Button2_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy