|
-
Mar 16th, 2010, 09:47 PM
#1
Thread Starter
New Member
-
Mar 17th, 2010, 01:30 AM
#2
Hyperactive Member
Re: Session? (Login from msql) Read for more info..
abt how to use session..
Session.Add("SessionName","YourValue");
// That's how u add value to session...
string username = Session["YouValue"].toString();
// Grab the value from session..
Next SHA Encryption.. try this SHA512 code and go to heaven
Code:
protected string MySHA512( )
{
SHA512 sha512 = new System.Security.Cryptography.SHA512Managed();
byte[] sha512Bytes = System.Text.Encoding.Default.GetBytes("vb.netdev");
byte[] cryString = sha512.ComputeHash(sha512Bytes);
string sha512Str = string.Empty;
for (int i = 0; i < cryString.Length; i++)
{
sha512Str += cryString[i].ToString("X");
}
return sha512Str;
}
hope that helps.
-
Mar 17th, 2010, 02:33 AM
#3
Re: Session? (Login from msql) Read for more info..
Hey,

When you say:
 Originally Posted by LeeMC89
I have added a login (required to use the application) and a register. Both login and register work (Fetching information from the database and writing to the database).
Do you mean that you have created your own code to do this? If so, have you thought about using the ASP.Net Membership, Profile and Roles Providers? They provide this functionality, out of the box, in a simple to implement manner. Including the functionality that you are now trying to add to the application.
Take a look at this very detailed walkthrough on what can be done using these providers:
http://www.4guysfromrolla.com/articles/120705-1.aspx
It is a big article, but well worth reading, and is broken down into logical chunks.
Gary
-
Mar 17th, 2010, 02:39 AM
#4
Re: Session? (Login from msql) Read for more info..
 Originally Posted by dnanetwork
Session.Add("SessionName","YourValue");
// That's how u add value to session...
string username = Session["YouValue"].toString();
// Grab the value from session..
This actually wouldn't work.
As per the documentation here:
http://msdn.microsoft.com/en-us/libr...state.add.aspx
The first parameter is the name, and the second parameter is the value. You in order to retrieve the value from the object collection, you would need to use this:
Code:
Session.Add("VariableName","VariableValue");
// That's how u add value to session...
string username = Session["VariableName"].ToString();
Alternatively, you can do this:
Code:
Session["VariableName"] = "VariableValue";
string username = Session["VariableName"].ToString();
Gary
-
Mar 17th, 2010, 07:15 AM
#5
Thread Starter
New Member
Re: Session? (Login from msql) Read for more info..
Hi,
Thanks for the replies, I'm a little confused now to how I'm supposed to create my program..?
So you are supposed to use asp.net for the login? or sessions? Because I read that asp.net is for creating websites, how does asp.net help me make a application?
Code:
Session.Add("VariableName","VariableValue");
// That's how u add value to session...
string username = Session["VariableName"].ToString();
So.. I'd add session.add to my login code and add a name to variablename (username) and variablevalue as (email)?
This is my code from the OK button (I used a basic tutorial and added the rest myself)
Code:
Dim conn As MySqlConnection
'connection to DB
conn = New MySqlConnection()
conn.ConnectionString = "server=******; user id=******; password=*****; database=*******;"
'see if connection filed.
Try
conn.Open()
Catch myerror As MySqlException
MessageBox.Show("Cannot connect to database: " & myerror.Message)
End Try
Dim myadapter As New MySqlDataAdapter
Dim sqlquary = "SELECT * FROM accounts WHERE email = '" & txtuser.Text & "' AND progpass = '" & txtpass.Text & "';"
Dim mycommand As New MySqlCommand
mycommand.Connection = conn
mycommand.CommandText = sqlquary
myadapter.SelectCommand = mycommand
Dim mydata As MySqlDataReader
mydata = mycommand.ExecuteReader()
If mydata.HasRows = 0 Then
MsgBox("This account does not exist!" & vbCrLf & vbCrLf & "To access the progam you need to register for a account.", _
vbExclamation, _
"ERROR - Invalid Username / Password.")
Else
MsgBox("Welcome to MyMediaUpload Desktop! " & txtuser.Text & vbCrLf & vbCrLf, _
vbExclamation, _
"Thanks for logging in.")
MMUDesktop.Show()
Me.Hide()
End If
Ok, so when I add the session in there how am I able to access the database to get data into the program? (as said in my previous post when a user logs in I want the program to then display information that is related to their account)
I'm just curious now to how I would now develop my application or how ASP.net is used with Visual Basic :/?..
Thanks.
-
Mar 17th, 2010, 07:33 AM
#6
Re: Session? (Login from msql) Read for more info..
 Originally Posted by LeeMC89
So you are supposed to use asp.net for the login? or sessions? Because I read that asp.net is for creating websites, how does asp.net help me make a application?
ASP.Net is a development platform which allows to you create Web Applications, Web Sites, and Web Services. Your web application/site will contain all the logic that is required to perform the operations that you want to take, such as, writing information into a Session Variable, or authenticating the user against information stored within a Database.
 Originally Posted by LeeMC89
Code:
Session.Add("VariableName","VariableValue");
// That's how u add value to session...
string username = Session["VariableName"].ToString();
So.. I'd add session.add to my login code and add a name to variablename (username) and variablevalue as (email)?
This is one way to do it, but I would suggest that this is quite a long way to do it. For each property that you want to make available, you would have to write code to do it. I would suggest that using the ASP.Net Profile Provider, that you will have much more flexibility.
 Originally Posted by LeeMC89
This is my code from the OK button (I used a basic tutorial and added the rest myself)
Code:
Dim conn As MySqlConnection
'connection to DB
conn = New MySqlConnection()
conn.ConnectionString = "server=******; user id=******; password=*****; database=*******;"
'see if connection filed.
Try
conn.Open()
Catch myerror As MySqlException
MessageBox.Show("Cannot connect to database: " & myerror.Message)
End Try
Dim myadapter As New MySqlDataAdapter
Dim sqlquary = "SELECT * FROM accounts WHERE email = '" & txtuser.Text & "' AND progpass = '" & txtpass.Text & "';"
Dim mycommand As New MySqlCommand
mycommand.Connection = conn
mycommand.CommandText = sqlquary
myadapter.SelectCommand = mycommand
Dim mydata As MySqlDataReader
mydata = mycommand.ExecuteReader()
If mydata.HasRows = 0 Then
MsgBox("This account does not exist!" & vbCrLf & vbCrLf & "To access the progam you need to register for a account.", _
vbExclamation, _
"ERROR - Invalid Username / Password.")
Else
MsgBox("Welcome to MyMediaUpload Desktop! " & txtuser.Text & vbCrLf & vbCrLf, _
vbExclamation, _
"Thanks for logging in.")
MMUDesktop.Show()
Me.Hide()
End If
Ok, so when I add the session in there how am I able to access the database to get data into the program? (as said in my previous post when a user logs in I want the program to then display information that is related to their account)
I'm just curious now to how I would now develop my application or how ASP.net is used with Visual Basic :/?..
Thanks.
First up, don't concatenate your SQL String like that. Doing so leaves you open to SQL injection attacks. If you take a look at the link in my signature regarding this, you will find a list of reasons why this is a bad idea.
Secondly, MsgBox, or rather MessageBox is a class within System.Windows.Forms and since you are creating a Web Application, you should not use this, so I would suggest that you remove it, in preference to adding logging to your application, or writing directly to a Label on your page.
ASP.Net is the platform, and the server side code that you write, in either VB.Net or C#, is what gets executed when the page loads.
As I have already mentioned, all of the above work is done for you if you use the ASP.Net Membership Provider, which I would guess that you already have installed, since you have MySqlConnection, which you would only get if you installed the MySql Connector for .Net.
Gary
-
Mar 17th, 2010, 05:47 PM
#7
Thread Starter
New Member
Re: Session? (Login from msql) Read for more info..
Ok Thanks I'll take a look into that ..
Sorry if I'm starting to sound really noobish.. Can I still make my application in VB?? (I want to make a windows application not a website, I think there has been some mix up somewhere as I probably still didn't explain properly.. Sorry DX.., I did post in the VB forum but it got moved here so I'm really confused..)
Sorry if I sound dumb I just still don't understand how it works, although I have looked through some guides...
Thanks for you help!
Last edited by LeeMC89; Mar 17th, 2010 at 05:51 PM.
-
Mar 18th, 2010, 03:00 AM
#8
Re: Session? (Login from msql) Read for more info..
Hey,
Don't worry about asking questions, everyone has to start somewhere, and no-one here will (or at least they shouldn't) slag you off for asking them.
Ok, back on topic....
Visual Studio as a whole lets to do lots of thing, for instance, create a Windows Application, a Windows Console Application, a Window Service, a Mobile Device Application, a Web Site, a Web Application, a Web Service etc.
Across all of these application types, you can create all of these in VB.Net or C# (notice I am limiting this to talking about the main managed languages, but there are other options if C++ is more your thing).
When it comes to ASP.Net Applications, i.e. web site, web service, web application, this is exactly the same. You can create your application in either VB.Net or C#. This is your server side code that I am talking about here. In addition to this, you will create your ASPX markup. This is what the ASP.Net engine will parse and convert to HTML for you, to display on the client machine.
Does that make sense?
So basically, your ASP.Net application will be a combination of ASPX markup, and either VB.Net or C# server side code.
Gary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|