dcsimg
Results 1 to 4 of 4

Thread: Declaring 'Crypto'?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    416

    Declaring 'Crypto'?

    Hello

    I am getting a compilation error because I have not declared 'Crypto' though I do have 'Imports System.Security.Cryptography' as a namespace.

    Name:  classCrypto.jpg
Views: 515
Size:  34.2 KB

    Would I need to generate Crypto as a class (please see screenshot for the light-bulb alternatives?

    Thank you.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,780

    Re: Declaring 'Crypto'?

    Quote Originally Posted by SteveHi View Post
    I do have 'Imports System.Security.Cryptography' as a namespace.
    Given that there's no type in that namespace named Crypto, I don't see how that would help.
    Quote Originally Posted by SteveHi View Post
    Would I need to generate Crypto as a class (please see screenshot for the light-bulb alternatives?
    You tell us. Types and members don't just appear out of thin air. If you think that the HashPassword method exists then you must think it exists somewhere. Where is that somewhere?

    My guess is that you have copied and pasted code form somewhere without a proper understanding of what it's actually doing. If that's the case then go back to the place you got the code form and read it carefully to find out exactly what they are referring to there. It may well be a class that they themselves wrote, in which case you need to copy that class into your project too. If you do that and you still can't work out what it is, at least provide us with a link to that source so that we can try to work out what it is.
    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

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    416

    Re: Declaring 'Crypto'?

    Hello jmcilhinny

    Thanks for your reply.

    I was reading this article https://brockallen.com/2012/10/19/pa...he-crypto-api/

    which explains that, in the code that I am using, 'the returned value contains both the salt and the hashed password in a single value. All you need to do is store the username and hashed password in your database.'

    Code:
    Public Sub CreateAccount(ByVal username As String, ByVal password As String)
            Dim hashedPassword = Crypto.HashPassword(password)
            CreateAccountInDatabase(username, hashedPassword)
        End Sub
    The password field ID on my form is 'password', and this is what I have at present:

    Code:
    Public Sub CreateAccount(ByVal username As String, ByVal password As String)
            Dim hashedPassword = Crypto.HashPassword(password)
            CreateAccountInDatabase(username, hashedPassword)
        End Sub
    
        Private Sub CreateAccountInDatabase(username As String, hashedPassword As Object)
            Throw New NotImplementedException()
        End Sub
    'CreateAccountInDatabase generated a 'not declared error' and the light-bulb proposed this Private Sub above
    'to overcome that error
    
        Private Sub CreateAccount(ByVal username As String, ByVal password As String, ByVal email As String)
            Dim hashedPassword = Crypto.HashPassword(password)
            Using connection As New OleDbConnection("connectionString")
    
                Dim Sql As String = "INSERT INTO university (username,strEmail,hashed) VALUES (@username,@strEmail,@hashed)"
    
                Dim cmd As New OleDbCommand(Sql)
                cmd.Connection = connection
    
                cmd.Parameters.AddWithValue("@username", username)
                cmd.Parameters.AddWithValue("@strEmail", email)
                cmd.Parameters.AddWithValue("@hashed", hashedPassword)
                connection.Open()
                cmd.ExecuteNonQuery()
    
            End Using
        End Sub
    Thanks again for your time.

    Steve

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,780

    Re: Declaring 'Crypto'?

    This is from the link you posted:
    Fortunately in ASP.NET (via the Crypto class in System.Web.Helpers.dll) they provide a wrapper on this and so you don’t even have to get involved with the details.
    That means that you'd have to have added a reference to that assembly for it to work but the only places I can find to that class mentioned are several years old and the System.Web.Helpers.dll assembly is no longer available. It was part of the Web Pages framework, which is no basically defunct as that functionality has been rolled into ASP.NET Core and/or MVC.

    Microsoft recommend the use of their own Identity framework nowadays, so you don't even have to do the hashing. You just call a method and pass the plain text and it will get hashed internally. If you want to manage your own user information, including hashed passwords, then you'll have to a do a bit more leg work.
    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