PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Not declared error-VBForums
Results 1 to 11 of 11

Thread: Not declared error

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    434

    Not declared error

    Hello

    Part of the code I have in my register.aspx.vb file which relates to salting/hashing looks like this:

    Code:
    Imports Microsoft.AspNet.Membership.OpenAuth
    Imports System
    Imports System.Linq
    Imports System.Web
    Imports System.Web.UI
    Imports System.Data.OleDb
    Imports System.Security.Cryptography
    Imports System.Text
    Imports System.Web.Helpers
    Code:
    Private Sub CreateAccount(ByVal username As String, ByVal password As String, ByVal email As String)
            Dim hashedPassword As String = Crypto.HashPassword(password)
    
            Using connection As New OleDbConnection("connectionString")
    
                Using cmd As New OleDbCommand("INSERT INTO university (username, strEmail, hashed) VALUES (@username, @strEmail, @hashed)", connection)
                    cmd.Parameters.AddWithValue("@username", username)
                    cmd.Parameters.AddWithValue("@strEmail", email)
                    cmd.Parameters.AddWithValue("@hashed", hashedPassword)
    
                    connection.Open()
                    cmd.ExecuteNonQuery()
                End Using
            End Using
        End Sub
    I am getting an error on the following line:

    Code:
    Dim hashedPassword As String = Crypto.HashPassword(password)
    since 'Crypto' is not declared. How would I rectify this error, please? I was told that by adding

    Code:
    Imports System.Web.Helpers
    at the top of my code would help, but I am still getting that crypto not declared error. It's driving me bananas.

    Thanks

    Steve

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,945

    Re: Not declared error

    Right... you never declared any where. What is it? What should it be? What are you expecting it to be?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    434

    Re: Not declared error

    Hello tq

    Since it is a text password, I would expect it to be String

    Thanks for your reply.

    Steve

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    434

    Re: Not declared error

    Hello tq

    Since it is a text password, I would expect it to be String

    Thanks for your reply.

    Steve

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,631

    Re: Not declared error

    I suspect that you have copied someone else's code from the web without an understanding of what that code actually does. The fact that you say "I would expect it to be String" strongly supports that. In this code:
    vb.net Code:
    1. Dim hashedPassword As String = Crypto.HashPassword(password)
    Crypto is obviously not a String because there's no HashPassword method in the String class. Go back to where you got that code from in the first place and read it properly to find out what that 'Crypto" actually is. It is probably a class that they wrote themselves that contains cryptographic functionality and that you need to also copy to your project.
    Last edited by jmcilhinney; Nov 15th, 2018 at 08:26 PM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Hyperactive Member
    Join Date
    Nov 2017
    Posts
    463

    Re: Not declared error

    I assume he meant that the result of Crypto.HashPassword(password) will be a String. And he's right, according to Microsoft's (the "they" that wrote it) documentation.

    https://docs.microsoft.com/en-us/dot...t-webpages-3.2

  7. #7
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,631

    Re: Not declared error

    Quote Originally Posted by OptionBase1 View Post
    I assume he meant that the result of Crypto.HashPassword(password) will be a String. And he's right, according to Microsoft's (the "they" that wrote it) documentation.

    https://docs.microsoft.com/en-us/dot...t-webpages-3.2
    That may be the case, but Crypto is what is not declared so Crypto is what tg is asking what it should be. That the OP didn't recognise that is just as much of a problem.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,631

    Re: Not declared error

    Quote Originally Posted by OptionBase1 View Post
    I assume he meant that the result of Crypto.HashPassword(password) will be a String. And he's right, according to Microsoft's (the "they" that wrote it) documentation.

    https://docs.microsoft.com/en-us/dot...t-webpages-3.2
    That said, that link indicates that this is a standard .NET class and so I was off the mark, but then that link that you provided is what the OP should have indicated based on tg's question. Regardless, the documentation does state that that type is specific to ASP.NET Web Pages, so it depends exactly what type of project the OP created as to whether that type will be available or not. @SteveHi, please specify EXACTLY what type of project you created.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,631

    Re: Not declared error

    Quote Originally Posted by SteveHi View Post
    I was told that by adding

    Code:
    Imports System.Web.Helpers
    at the top of my code would help, but I am still getting that crypto not declared error.
    You should probably learn about assemblies and namespaces too. I suggest that you follow the Blog link in my signature and read my post on the subject. That line simply imports a namespace, which means that you can use members of that namespace unqualified in that code file. It doesn't magically give you access to members of that namespace that your project doesn't know exist. You still need to reference the assembly that that Crypto class is declared in and you may not be able to do that, depending on the type of project you created.

    ASP.NET Web Pages was a technology that Microsoft created a while back to make it easier for beginners to get into ASP.NET development. Instead of using Web Forms or MVC in Visual Studio, you could use Web Pages in WebMatrix. WebMatrix is now defunct and some of its functionality and some of that of Web Pages as been absorbed into VS and other ASP.NET technologies. Only some though.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    434

    Re: Not declared error

    This is a Web Forms project.

    In the line of code that I originally posted and that was giving me the 'Crypto' not declared error, that is

    Code:
    Dim hashedPassword As String = Crypto.HashPassword(password)
    don't I need to relate the 'hashedPassword' in the above line with the 'hashedPassword' in the line of code that follows, namely:

    Code:
    cmd.Parameters.AddWithValue("@hashed", hashedPassword)
    So I could have something like this (not tried it yet):

    Code:
    Dim Crypto As Whatever
    
    Crypto = Crypto.hashedPassword(password)
    Thanks again.

  11. #11
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,631

    Re: Not declared error

    Your 'hashedPassword' variable is irrelevant. The error message is that 'Crypto' is not declared. That's the issue. In this line of code:
    vb.net Code:
    1. Dim hashedPassword As String = Crypto.HashPassword(password)
    you are declaring a variable named 'hashedPassword' of type String and initialising it with the value returned by Crypto.HashPassword. The issue is that the compiler has no idea what Crypto is. It appears that you intended it to be the System.Web.Helpers.Crypto class but your project has no idea that that class exists if you don't reference the assembly that it's declared in, i.e. System.Web.Helpers.dll.

    I'm not sure whether it's possible for you to reference that assembly or not because, strictly speaking, it's not part of Web Forms. It is part of Web Pages and not everything that was part of Web Pages survived its being axed as a standalone technology. Try adding the reference and, if you can, that should solve your issue. If you can't then you won't be able to use that class and will have to find some other way to hash the password. That's not especially difficult as you will just have to use the same classes directly that that Crypto class uses internally. That's how everyone else hashed passwords before that Crypto class anyway.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width