Encrypt the password with the MD5, and determine that the user ID is already

zhaozj2021-02-17  64

First, create a USER table, field 3: ID, userid, and password, type INT (4), varchar (25), and binary (16). Set the ID to the automatic increase of the primary key. Userid is set to the only type constraint ---------------------------------------------------------------------------------------------------------------------------------------------------------------- -------- Add user calling stored procedure Create Procedure Sp_USERADD (@Userid varchar (20), @user_id int outprut AS INSERT INTO USER (userid, password) VALUES (@ Userid, @ password) select @user_id = @@ identity - get the id that is just inserted, note that the value of the field ID is not the value of the userid field -------------------------------- ------------------------------------ The program is judged according to the return value of @user_id (if the record is added Success will return the current ID number, select @user_id = @@ identity. In order to explain that the currently adding userid has a repetition value in the database, will not be able to get the new ID number.) The following code is based on this Point to judge.

-------------------------- Background code: Import system.text import system.data.sqlclient import system.seircurity.cryptography 'encrypted class' Add User Functions SUB Adduser (Byval Struserid AS String) '1. Create a connection DIM STRCONNSTRING AS STRING' Connection Character to modify strConnstring = "data source = .; initial catalog = test; user id = sa; Password =; "Dim objConn as New SqlConnection (strConnString) '2. Create Command object Dim objCmd as New SqlCommand (" Sp_UserAdd ", strConnString) objCmd.CommandType = CommandType.StoredProcedure' 3. Create parameter 'Create userid Dim paramUserid as input parameters SqlParameter paramUserid = New SqlParameter ( "@ Userid", SqlDbType.VarChar, 25) paramUserid.Value = struserid objCmd.Parameters.Add (paramUserid) 'encrypted password field Dim md5Hasher as New MD5CryptoServiceProvider () Dim hashedBytes as Byte () Dim encoder as New utf8encoding () Hashedbytes = md5hasher.computehash (encoder.getbytes) 'Creating an input parameter Password Dim parampassword as SqlParameter parampassword = New SqlParameter ( "@ Password", SqlDbType.Binary, 16) parampassword.Value = hashedBytes objCmd.Parameters.Add (parampassword) 'to create the output parameter Pkid Dim paramPkid as SqlParameter paramPkid = New SqlParameter ( "@ Pkid" , SqlDbType.int, 4) paramPkid.Direction = ParameterDirection.Output objCmd.Parameters.Add (paramPkid) try objConn.Open () objCmd.ExecuteNonQuery () objConn.Close () 'obtained return value stored procedure dim user_Id as integer =

转载请注明原文地址:https://www.9cbs.com/read-30580.html

New Post(0)