:: Think Code Execute ::

June 9, 2009

:: Md5 Encryption C#.net ::

Filed under: c#.net — eshbeata @ 10:51 pm
Tags: , ,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
/// <summary>
/// Summary description for db
/// </summary>
public class db
{
public static string connectionstring = @”Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True”;
public db()
{
//
// TODO: Add constructor logic here
//
}
//function login for string
public bool login(string user, string pass)
{
//connection to the database
SqlConnection con = new SqlConnection(connectionstring);
//sql query to retreive data
string sql = “select password from student where student_id =  @user”;
//sql paramterize to secure the sql injection attack
SqlParameter pl = new SqlParameter(”@user”, user);
//sql command
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.Add(pl);
//open the connection
con.Open();
//reader to excute the sql query of sql command
SqlDataReader rdr = cmd.ExecuteReader();
bool log = false;
//check if the reader can read
if (rdr.Read())
{
//conver the password to md5 hash encryption
string password = GetMD5Hash(pass);
//check if the password equal the pass in database
if (rdr[0].ToString() == password)
{
log = true;
}
}
//close the reader
rdr.Close();
//close the connection
con.Close();
return log;
}
//md5 function ecryption
public string GetMD5Hash(string input)
{
System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] bs = System.Text.Encoding.UTF8.GetBytes(input);
bs = x.ComputeHash(bs);
System.Text.StringBuilder s = new System.Text.StringBuilder();
foreach (byte b in bs)
{
s.Append(b.ToString(”x2″).ToLower());
}
string password = s.ToString();
return password;
}
//admin login function
public bool login_admin(string user, string pass)
{
SqlConnection con = new SqlConnection(connectionstring);
string sql = “select password from Admin where username = @user”;
SqlParameter pl = new SqlParameter(”@user”, user);
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.Add(pl);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
bool log = false;
if (rdr.Read())
{
string password = GetMD5Hash(pass);
if (rdr[0].ToString() == password)
{
log = true;
}
}
rdr.Close();
con.Close();
return log;
}
//get the vote of each nomine to view it in result
public string get_voting(string id)
{
SqlConnection con = new SqlConnection(connectionstring);
string sql = “select vote from nomeni where Student_ID= ‘”+ id + “‘ “;
SqlCommand cmd = new SqlCommand(sql, con);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
string vote = “”;
if (rdr.Read())
{
vote = rdr[0].ToString();
}
rdr.Close();
con.Close();
return vote;
}
//get the statiscits data
public string [] set_election_year()
{
SqlConnection con = new SqlConnection(connectionstring);
string sql = “select count(*) , sum(vote) from student”;
SqlCommand cmd = new SqlCommand(sql, con);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
string vote = “”;
string unvote = “”;
if (rdr.Read())
{
unvote = rdr[0].ToString();
vote = rdr[1].ToString();
}
rdr.Close();
con.Close();
string[] x = new string[2];
x[0] = unvote;
x[1] = vote;
return x;
}
//check if student id already exist in adduser page
public bool check_user_exist(string user)
{
SqlConnection con = new SqlConnection(connectionstring);
string sql = “select student_id from student where student_id = ‘” + user + “‘”;
SqlCommand cmd = new SqlCommand(sql, con);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
bool log = false;
if (rdr.Read())
{
if (rdr[0].ToString() == user)
{
log = true;
}
}
rdr.Close();
con.Close();
return log;
}
//get nomine data to view it on vote page
public SqlDataReader  get_nomine(string user)
{
SqlConnection con = new SqlConnection(connectionstring);
string sql = “select * from nomeni where student_id = ‘” + user + “‘”;
SqlCommand cmd = new SqlCommand(sql, con);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
bool log = false;
rdr.Read();
return rdr;
}
//get date time data
public SqlDataReader get_year()
{
SqlConnection con = new SqlConnection(connectionstring);
string sql = “select * from timedate”;
SqlCommand cmd = new SqlCommand(sql, con);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
rdr.Read();
return rdr;
}
//check if student already vote
public string checkvoting(string user)
{
SqlConnection con = new SqlConnection(connectionstring);
string sql = “select vote from student where student_id = ‘” + user + “‘”;
SqlCommand cmd = new SqlCommand(sql, con);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
string vote = “”;
if (rdr.Read())
{
vote = rdr[0].ToString();
}
rdr.Close();
con.Close();
return vote;
}
public void voting(string std_id)
{
}
}

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Data.SqlClient;

/// <summary>

/// Summary description for db

/// </summary>

public class db

{

public static string connectionstring = @”Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True”;

public db()

{

//

(more…)

:: Imagine Cup Interoperability Award Winner ::

Filed under: :: Windows :: — eshbeata @ 11:25 am
Tags: , ,
Interoperability Award:

Country/Region Finalist Team Name
Jordan ECRAM
Poland fteams
Brazil Proativa Team

my Ecram Team had won in the Interoperability Award World Wide Competition on Microsofot Imagine Cup

Can’t Wait to go To Egypt :)

March 4, 2009

:: Building an N-Tier Application in .NET ::

Filed under: :: Asp.net :: — eshbeata @ 6:44 pm
Tags: , , ,

Introduction : 

a lot of people think that building a N-tier application is so diffucult

but to think about it , its alot easy and make sense

its just make partion of the project

 

Background

N-Tier is a Client-Server Architecture in which User interface (Presentation Layer), Business Rules(Business Logic Layer), Data Access(Data Layer) are separated in Layers, maintained and Developed Indipendently. The Applicatin will be broken into Tiers. Presentation Layer will be your Form or ASP.NEt page, Busines Layer will be the Classes that will Check if the Business Rules have not been Violeted, and the Data Access layer will Accept the Validated Data from the Business Logic layer and run the SQl commands on the Actual Database.

 

n-tier

as you see in the figure below this is the Architecture of the N-Tier application

 

  1. Presentation Layer : contain all user interface and GUI , including ASp.net pages … etc
  2. Business Layer: contain all rules and class to manupliate the logaical of the application and communicate with the Data Access Layer
  3. Data Access Layer : here is where the Stored Procuder are , class that handle Data Base connection .

Have a Nice Day ^_^

January 26, 2009

:: Install MS Bluetooth Stack ::

Filed under: :: Windows :: — eshbeata @ 2:12 pm
Tags: , ,

my problem was to install to microsofot bluetooth stack inseted of any other

bluetooth stack

the solution is simple :D

just donload the file here click here

rename the file bth.jpg  to bth.inf 

 

now go to devic manager and to you bluetooth driver

and find theVid_044e&Pid_3005

then open the  bth.inf

and go under the ——- Device section – Start —–

and add this

device name=                BthUsb, USB\Vid_044e&Pid_3005 

change th vid, pid value to your device values

save the file

go to the driver and update your drive 

and chose to locate file driver bth.inf

and thats it:)

January 15, 2009

:: How To Run CMD Dos Command in C#.net ::

Filed under: c#.net — eshbeata @ 2:31 am
Tags: , , ,

Its easy you only need to use process :)

System.Diagnostics.Process.Start(”CMD.exe”,”cd ..”);

this how we do it :)

if you need to terminate the dos after excution the dos command you just need to put /C

System.Diagnostics.Process.Start(”CMD.exe”,”/C dir”);

you also can yous multiple dos command at the same time like
System.Diagnostics.Process.Start(”CMD.exe”,@”/C cd\ & myapp.exe “);

have a nice day :)

Next Page »

Blog at WordPress.com.