Post: Quick question..
12-18-2013, 12:50 AM #1
(adsbygoogle = window.adsbygoogle || []).push({}); Can someone tell me how to validate network credentials?

I'm making a program that needs the user to log on their email with their email and password, but throws an error if there's something wrong with their log-on details.

I used a try function, and catch ex as exception I just need to know what to put after when, I tried using it without when, but it won't throw an error.

Code:

Try
Dim pceout As New SmtpClient

pceout.Credentials = New Net.NetworkCredential(Email.Text, Password.Text)
pceout.Port = Port.Text
If ComboBox1.Text = "Gmail" Then
pceout.Host = "smtp.gmail.com"
ElseIf ComboBox1.Text = "Yahoo" Then
pceout.Host = "smtp.mail.yahoo.com"
ElseIf ComboBox1.Text = "Hotmail" Then
pceout.Host = "smtp.live.com"
ElseIf ComboBox1.Text = "AOL" Then
pceout.Host = "smtp.aol.com"
End If
Button3.Enabled = True
Catch ex As Exception
MsgBox("Error")
Button3.Enabled = False


End Try
(adsbygoogle = window.adsbygoogle || []).push({});
12-18-2013, 06:38 AM #2
If you're using your own database, just call the tables. If the values equals something inside the tables, allow. If not, throw such an error.
12-18-2013, 06:41 AM #3
I'm not using a database, the program will use one of those email servers to log on with.. If the account isn't right, it should throw an error but it wont. The program just doesn't do anything, since the network credentials are invalid.
12-24-2013, 02:35 AM #4
Default Avatar
Oneup
Guest
If you are trying to use a try catch you need to understand what happens where.

In the catch block is where you will get your error message.You can either have it print out what you want it to say or you can have it throw the actually exception

So something like:
    
Try

Catch ex as exception

Messagebox.show(ex.tostring)

End Try


12-24-2013, 02:38 AM #5
I dont get it.. When I do that, it only throws the error whenever the textbox is empty. It doesn't throw an error if the email or password is wrong..
12-24-2013, 02:43 AM #6
Default Avatar
Oneup
Guest
Originally posted by TorqueLewith View Post
I dont get it.. When I do that, it only throws the error whenever the textbox is empty. It doesn't throw an error if the email or password is wrong..


Well its going to trip on the first thing that will cause the program to crash. Since you are trying to establish a connection first with
pceout.Credentials = New Net.NetworkCredential(Email.Text, Password.Text)

it's going to fail and drop to the catch since the textboxes are empty
12-24-2013, 02:45 AM #7
Originally posted by 1UP View Post
Well its going to trip on the first thing that will cause the program to crash. Since you are trying to establish a connection first with
pceout.Credentials = New Net.NetworkCredential(Email.Text, Password.Text)

it's going to fail and drop to the catch since the textboxes are empty

Oh, okay.. So would I put the catch block at the top before dimming the credential, then another one after..?
12-24-2013, 02:49 AM #8
Default Avatar
Oneup
Guest
Originally posted by TorqueLewith View Post
Oh, okay.. So would I put the catch block at the top before dimming the credential, then another one after..?


Well you could just do if statements before you do a try catch to test to make sure each individual textbox is filled out.
12-24-2013, 02:59 AM #9
Originally posted by 1UP View Post
Well you could just do if statements before you do a try catch to test to make sure each individual textbox is filled out.

What would I put after an if, if i wanted to check their network credentials to make sure their email or password is right?
12-24-2013, 03:09 AM #10
Default Avatar
Oneup
Guest
Originally posted by TorqueLewith View Post
What would I put after an if, if i wanted to check their network credentials to make sure their email or password is right?


Well this is how I would do it

    
Dim ErrorMessage as string = ""

'Check that textboxes aren't empty
If txtEmail.text = "" Then ErrorMessage ="Please enter an Email Address!" & Environment.newline
If txtPassword.text = "" Then ErrorMessage ="Please enter a password!" & Environment.newline


If ErrorMessage ="" then
Try

Catch

End Try

Else
Messagebox.show(ErrorMessage)
End If

You could do something like this

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo