Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CONVERSION ERROR: Code could not be converted. Details: -- line 1 col 9: invalid TypeDecl

Status
Not open for further replies.

primagic

IS-IT--Management
Jul 24, 2008
476
GB
Trying to convert the following code to vb.net but getting an error


Code:
private bool VerifyPassword(string suppliedUserName,
                            string suppliedPassword )
{ 
  bool passwordMatch = false;
  // Get the salt and pwd from the database based on the user name.
  // See "How To: Use DPAPI (Machine Store) from ASP.NET," "How To:
  // Use DPAPI (User Store) from Enterprise Services," and "How To:
  // Create a DPAPI Library" for more information about how to use
  // DPAPI to securely store connection strings.
  SqlConnection conn = new SqlConnection( "Server=(local);" +
                                          "Integrated
                                            Security=SSPI;" +
                                          "database=UserAccounts");
  SqlCommand cmd = new SqlCommand( "LookupUser", conn );
  cmd.CommandType = CommandType.StoredProcedure;
  //Usage of Sql parameters also helps avoid SQL Injection attacks.
  SqlParameter sqlParam = cmd.Parameters.Add("@userName",
                                             SqlDbType.VarChar,
                                               20);
  sqlParam.Value = suppliedUserName;
  try
  {
    conn.Open();
    SqlDataReader reader = cmd.ExecuteReader();
    reader.Read(); // Advance to the one and only row
    // Return output parameters from returned data stream
    string dbPasswordHash = reader.GetString(0);
    int saltSize = 5;
    string salt = 
      dbPasswordHash.Substring(dbPasswordHash.Length - saltSize);
    reader.Close();
    // Now take the password supplied by the user
    // and generate the hash.
    string hashedPasswordAndSalt =
      CreatePasswordHash(suppliedPassword, salt);
    // Now verify them.
    passwordMatch = hashedPasswordAndSalt.Equals(dbPasswordHash);
  }
  catch (Exception ex)
  {
    throw new Exception("Execption verifying password. " +
      ex.Message);
  }
  finally
  {
    conn.Close();
  }
  return passwordMatch;
}
 
This is C#.
What do you know about VB?

private [highlight #EF2929]bool[/highlight] VerifyPassword(string suppliedUserName, string suppliedPassword

==>
VerifyPassword(suppliedUserName [highlight #4E9A06]as String[/highlight]...) [highlight #4E9A06]as bool[/highlight]

:)

It's the little things...

“Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.” (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
 
It would help if you told us the error you are getting and on what line of code.
 
jbenson001, he is not getting error it is C# code not VB. As MakeItSo mentioned
conversion is simple

private bool VerifyPassword(string suppliedUserName,
string suppliedPassword )
should be
private VerifyPassword(suppliedUserName as string,
suppliedPassword as string) as bool
no ";" after each statement
and etc, just loock on VB standard...
 
If you read the post, the OP says they are getting an error trying to convert the code.
Trying to convert the following code to vb.net but getting an error
So the question still remains, what has been converted, and what line of code is causing the error.
 
The error and location of the code is in the title - line 1 col 9: invalid TypeDecl

got it sorted thanks
 
However my validation code below always returns invalid username/password but I know the credentials I enter are correct.

Code:
Private Function VerifyPassword(SuppliedUsername As String, SuppliedPassword As String) As Boolean

        Dim passwordMatch As Boolean = False
        ' Get the salt and pwd from the database based on the user name.
        ' See "How To: Use DPAPI (Machine Store) from ASP.NET," "How To:
        ' Use DPAPI (User Store) from Enterprise Services," and "How To:
        ' Create a DPAPI Library" for more information about how to use
        ' DPAPI to securely store connection strings.

        Dim ConnString As [String] = ConfigurationManager.ConnectionStrings("HostLinkConnectionString").ConnectionString
        Dim con As New SqlConnection(ConnString)
        Dim cmd As New SqlCommand()
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "spLookupUser"
        cmd.Parameters.Add("@Username", SqlDbType.NVarChar).Value = SuppliedUsername

        Try

            cmd.Connection = con

            con.Open()

            Dim reader As SqlDataReader = cmd.ExecuteReader()
            reader.Read()
            ' Advance to the one and only row
            ' Return output parameters from returned data stream
            Dim dbPasswordHash As String = reader.GetString(0)

            Dim saltSize As Integer = 5
            Dim salt As String = dbPasswordHash.Substring(dbPasswordHash.Length - saltSize)
            reader.Close()

            ' Now take the password supplied by the user and generate the hash.

            Dim hashedPasswordAndSalt As String = CreatePasswordHash(SuppliedPassword, salt)
            ' Now verify them.
            passwordMatch = hashedPasswordAndSalt.Equals(dbPasswordHash)



        Catch ex As Exception
            Throw New Exception("Execption verifying password. " + ex.Message)
        Finally
            con.Close()

        End Try
        Return passwordMatch

    End Function

it seems to create a different hash so it won't ever match

 
You have to know and use the same salt and hash that you are using when you create the password
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top