Results 1 to 15 of 15

Thread: [RESOLVED] SQL Server Password data type

  1. #1

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Resolved [RESOLVED] SQL Server Password data type

    Is there a password data type in SQL server like in access so I can store passwords in the database but so they are displayed as stars rather than plain text.

  2. #2
    Lively Member
    Join Date
    Jun 2005
    Location
    AZ
    Posts
    67

    Re: SQL Server Password data type

    I know in Access you have that option in the format section of the Table design maybe you can place that format in the Gui form.. if you are retrieving and/or entering information from it....

    But as for the SQL design I haven't found anything maybe others more experienced may know something

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: SQL Server Password data type

    Short answer: No.

    Slightly longer answer: It's generaly a bad idea to store passwords in the database. But if you *must*, then encrypt it. When you need to check it you can then do one of two things:
    1) Encrypt the entered password (presumably by the user) and compare that to the encrypted value stored. or..
    2) Decrypt the stored value and compare that to what was entered.

    Option 1 is the more secure.

    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??? *

  4. #4
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: SQL Server Password data type

    To add to what TG has said - use option 1 with a "one-way only encryption algorithm". Passwords should not be able to be decrypted, in my opinion.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  5. #5
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: SQL Server Password data type

    One "cunning" idea I have is to encrypt your password then "embed" it in an image then save it in your database.... That way even if somebody will be manipulating your database they wouldnt see an encrypted string.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  6. #6

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: SQL Server Password data type

    Ok thanks for the replies guys, what method do you recommend for the encryption, use a third party add in or devise my own algorithm? Just to give you some background all I have is a basic vb.net form which allows the user to enter a username and password, the form looks up the username and password if the passwords match it allows the execution of the app to continue.

  7. #7
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: SQL Server Password data type

    Of course it would be better if you would devise your own algorithm so it would be difficult to decrypt.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  8. #8

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: SQL Server Password data type

    Sorry if im being a silly billy what kind of thing do you mean would something like reading in the string entered and multiplying each character value by a number then dividing it by another etc be the knd of thing or am I being two simplistic.

  9. #9
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: SQL Server Password data type

    Well, that is how the encryption process is done, it would all depend to you.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  10. #10
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [RESOLVED] SQL Server Password data type

    I suggest using a pre-built tried and true method. They exist for a reason. If you only want to do one way encryption, then MD5 is the way to go.

    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??? *

  11. #11

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: [RESOLVED] SQL Server Password data type

    techgnome - do you know where i can find out how to use MD5 i.e what i download and from where and how reference it.

  12. #12
    Fanatic Member -TPM-'s Avatar
    Join Date
    Jul 2005
    Posts
    850

    Re: [RESOLVED] SQL Server Password data type

    I'd suggest you read through these:
    This one's about salt
    http://www.developerfusion.co.uk/show/4679/
    This one's about different encryption type's, they use SHA for the Hash (page3) which is similar to MD5
    http://www.devx.com/security/Article/7019/
    TPM

    Add yourself to the VBForums Frappr Map!!

  13. #13

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: [RESOLVED] SQL Server Password data type

    For anyone else I have this working fine now thanks all for your help :-)
    VB Code:
    1. Public Class PasswordGenerator
    2.  
    3.     Inherits System.Windows.Forms.Form
    4.  
    5.  
    6. #Region " Windows Form Designer generated code "
    7.  
    8.     Public Sub New()
    9.         MyBase.New()
    10.  
    11.         'This call is required by the Windows Form Designer.
    12.         InitializeComponent()
    13.  
    14.         'Add any initialization after the InitializeComponent() call
    15.  
    16.     End Sub
    17.  
    18.     'Form overrides dispose to clean up the component list.
    19.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    20.         If disposing Then
    21.             If Not (components Is Nothing) Then
    22.                 components.Dispose()
    23.             End If
    24.         End If
    25.         MyBase.Dispose(disposing)
    26.     End Sub
    27.  
    28.     'Required by the Windows Form Designer
    29.     Private components As System.ComponentModel.IContainer
    30.  
    31.     'NOTE: The following procedure is required by the Windows Form Designer
    32.     'It can be modified using the Windows Form Designer.  
    33.     'Do not modify it using the code editor.
    34.     Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    35.     Friend WithEvents Label1 As System.Windows.Forms.Label
    36.     Friend WithEvents Label2 As System.Windows.Forms.Label
    37.     Friend WithEvents Button1 As System.Windows.Forms.Button
    38.     Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    39.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    40.         Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(PasswordGenerator))
    41.         Me.TextBox1 = New System.Windows.Forms.TextBox
    42.         Me.Label1 = New System.Windows.Forms.Label
    43.         Me.Label2 = New System.Windows.Forms.Label
    44.         Me.Button1 = New System.Windows.Forms.Button
    45.         Me.TextBox2 = New System.Windows.Forms.TextBox
    46.         Me.SuspendLayout()
    47.         '
    48.         'TextBox1
    49.         '
    50.         Me.TextBox1.Location = New System.Drawing.Point(8, 40)
    51.         Me.TextBox1.Name = "TextBox1"
    52.         Me.TextBox1.Size = New System.Drawing.Size(272, 20)
    53.         Me.TextBox1.TabIndex = 0
    54.         Me.TextBox1.Text = ""
    55.         '
    56.         'Label1
    57.         '
    58.         Me.Label1.Location = New System.Drawing.Point(8, 16)
    59.         Me.Label1.Name = "Label1"
    60.         Me.Label1.TabIndex = 1
    61.         Me.Label1.Text = "Enter a Phrase"
    62.         '
    63.         'Label2
    64.         '
    65.         Me.Label2.Location = New System.Drawing.Point(8, 104)
    66.         Me.Label2.Name = "Label2"
    67.         Me.Label2.TabIndex = 2
    68.         Me.Label2.Text = "Your Password Is"
    69.         Me.Label2.Visible = False
    70.         '
    71.         'Button1
    72.         '
    73.         Me.Button1.Location = New System.Drawing.Point(96, 72)
    74.         Me.Button1.Name = "Button1"
    75.         Me.Button1.TabIndex = 4
    76.         Me.Button1.Text = "Generate"
    77.         '
    78.         'TextBox2
    79.         '
    80.         Me.TextBox2.Location = New System.Drawing.Point(8, 128)
    81.         Me.TextBox2.Multiline = True
    82.         Me.TextBox2.Name = "TextBox2"
    83.         Me.TextBox2.ReadOnly = True
    84.         Me.TextBox2.Size = New System.Drawing.Size(280, 72)
    85.         Me.TextBox2.TabIndex = 5
    86.         Me.TextBox2.Text = ""
    87.         '
    88.         'PasswordGenerator
    89.         '
    90.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    91.         Me.ClientSize = New System.Drawing.Size(292, 213)
    92.         Me.Controls.Add(Me.TextBox2)
    93.         Me.Controls.Add(Me.Button1)
    94.         Me.Controls.Add(Me.Label2)
    95.         Me.Controls.Add(Me.Label1)
    96.         Me.Controls.Add(Me.TextBox1)
    97.         Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
    98.         Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
    99.         Me.MaximizeBox = False
    100.         Me.Name = "PasswordGenerator"
    101.         Me.Text = "Password Generator"
    102.         Me.ResumeLayout(False)
    103.  
    104.     End Sub
    105.  
    106. #End Region
    107.     Public Function GetHashValue(ByVal strInput As String) As String
    108.         Try
    109.  
    110.             Dim md5 As New System.Security.Cryptography.MD5CryptoServiceProvider
    111.             Dim hash As Byte()
    112.             Dim b As Byte()
    113.             Dim hashedString As String
    114.             '
    115.             b = System.Text.Encoding.UTF8.GetBytes(Trim(strInput))
    116.             hash = md5.ComputeHash(b)
    117.             hashedString = System.Convert.ToBase64String(hash)
    118.             '
    119.             ' return the output string
    120.             GetHashValue = hashedString
    121.  
    122.         Catch
    123.             GetHashValue = ""
    124.         End Try
    125.     End Function
    126.  
    127.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    128.         Me.TextBox2.Text = GetHashValue(Me.TextBox1.Text)
    129.     End Sub
    130. End Class

  14. #14
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [RESOLVED] SQL Server Password data type

    .NET has that stuff build in under the System.Encryption (I think that's the right namespace) that can encrypt/decrypt and hash data for you.

    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??? *

  15. #15

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: [RESOLVED] SQL Server Password data type

    Yes thanks techgnome, thats what I missed on my code I posted above the class declaration. I actually used Imports System.Security.Cryptography.
    Sorry I didnt mean to posts all the windows generated code.
    Anyway Thats my database stored password encrytion done now, I have created an app like above just to generate the passwords, as an admin utility. The acual app the user sees encrypts the password they enter and compares it to the one in the database.

Posting Permissions

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



Click Here to Expand Forum to Full Width