User management

zhaozj2021-02-11  215

Use the ASP file operation to implement user management

Simple, easy to use, development efficiency, etc. is the advantage of ASP, but its system operation is relatively weak. To achieve this function, only the way to call components. FileSystemObject object is an example. After the ASP is installed, the object is registered in the system. However, its feature is also very general, only file type files can be operated. But you can also meet some of our needs. A friend of a colleague in the past few days applied for a space that supported the ASP, wanted to implement functions such as user registration, information modification, user logout, and do not want to use the database to implement, because a lot of settings are required. In fact, the text file is operated using the FileSystemObject. The implementation is: establish a text file for each information, such as name, gender, age, etc. All users' same information items are saved in the corresponding file. If the name information of each user is saved in the name file. And each user's information begins and ends and ends, and the information is positioned based on these flags. For example, start the flag with "` user name ", end the flag with" `e`. As long as it is not a common string, it can be used as a flag. In addition, there are two files that are essential: That is the username, password file. Determine if the user exists, the user login, etc., the use of these two files. The following is the specific implementation code of myself. Before the program was written, I first made a public function unit Fun.inc, which is some relatively universal functions for other ASP files. First of all, the functions of some user information, including the username, file name, user information, are all string type, where user information can be multi-line. Code is as follows: Sub WriteUser (UserName, FileName, UserInfo) Dim fs, f Set fs = CreateObject ( "Scripting.FileSystemObject") If fs.FileExists (FileName) = False Then fs.CreateTextFile (FileName) End If 'to add Open File set f = fs.opentextfile (filename, 8) 'User information Start flag F.WriteLine ("` "& username &" `") F.Writeline ("` Er) end sign F.Writeline ("` E` ") F.close set f = nothing set fs = nothingend Sub read user information function only requires two parameters: user name and file name, user information as the return value of the function, the implementation of the idea is to find the beginning, end the flag, and Return the information between them.

Code is as follows: Function ReadUser (UserName, FileName) Dim i Dim s Dim ret Dim fs, f Set fs = CreateObject ( "Scripting.FileSystemObject") if fs.FileExists (FileName) = false then Set fs = Nothing ReadUser = "" Exit Function end if 'open files in read-only mode Set f = fs.opentextfile (filename, 1) do while f.atendofstream <> true s = f.readline if s = "` "& username &" `` "THEN S = f .Readline ret = "" Do while s <> "` E` "if Ret =" "" "= RET S ELSE RET = RET CHR (13) & chr (10) s end if s = f.readline LOOP EXIT Do End if Loop F.Close Set F = Nothing Set FS = Nothing Readuser = Retend Function The following is a function of deleting user information, using two parameters of the username and file name. The program reads the corresponding file by line. If other users' information, saved in a string variable, otherwise, the file is not saved, and then the file is overridden with the contents of the variable.

Code is as follows: Sub DeleteUser (UserName, FileName) Dim i Dim s Dim tmp Dim fs, f Set fs = CreateObject ( "Scripting.FileSystemObject") if fs.FileExists (FileName) = false then Set fs = Nothing Exit Sub end if Set f = fs.opentextfile (filename, 1) TMP = "" DO while f.atendofstream <> true s = f.readLine if s <> "` "& username &" `" THEN IF TMP = "" THENTMP = TMP S else TMP = TMP CHR (13) & chr (10) s end if Else do while s <> "` e` "s = f.readline loop end if loop f.close set f = fs.createtextfile FileName, True) F.WriteLine Tmp F.Close Set f = nothing set fs = nothingnd Sub Modify the user information function and the write user information function, with the username, file name, user information three parameters, only this function User information is updated. The process of implementation and deletion of the program is similar, deleting the user does not save the user's information to the variable, modify the user, save the update information to the variable instead of the original information.

Code is as follows: Sub ModifyUser (UserName, FileName, NewUserInfo) Dim i Dim s Dim tmp Dim fs, f Set fs = CreateObject ( "Scripting.FileSystemObject") if fs.FileExists (FileName) = false then Set fs = Nothing Exit Sub end IF set f = fs.opentextfile (filename, 1) TMP = "" Do while f.atendofstream <> true s = f.readline if s <> "` "& username &" `" Then IF TMP = "" THEN TMP = TMP S ELSE TMP = TMP CHR (13) & chr (10) S end if Else do while s <> "` e` "s = f.readline loop if TMP =" "" TMP = TMP " `" & Username & "` "Else TMP = TMP CHR (13) & chr (10) " `" & username & "` "end if TMP = TMP CHR (13) & chr (10) NewuserInfo TMP = TMP CHR (13) & chr (10) "` E. Endiff f.close set f = fs.createtextfile (filename, true) F.WriteLine Tmp F.Close set f = nothing set fs = nothingend Sub has a function to determine if the user exists, and is implemented by positioning in a file saved username, the code is as follows: function useerexist (username, filename) DIM FS, F set fs = CreateObject ( "Scripting.FileSystemObject") if fs.FileExists (FileName) = False then Set fs = Nothing UserExist = False Exit Function end if Set f = fs.OpenTextFile f.AtEndOfStream (FileName, 1) Do While <> True s = F.Readline if s = "` "& username &" `" Then usexist =

True EXIT FUNCTION End if loop f.close set f = nothing set fs = Nothing useEREXIST = FALSEEND function The following is the full code of some files, demonstrate how to implement basic user management by calling the above functions: User registration, user login, user Modify, user delete. for reference only. The program is commissioned in Win2000 Professional IIS. Note that the text file is saved under the subdirectory "TXT" of the current directory, if there is no this directory, please establish it manually, and the program is implemented.

'*********************************************************** ************* <% DIM Usernmfile, UserPwdFile, Nmfile, Gnderfile, MMFileUsernmfile = "txt / username.txt" userpwdfile = "txt / password.txt" nmfile = "txt / name. txt "GenderFile =" txt / Gender.txt "MmFile =" txt / memo.txt "UserNmFile = Server.MapPath (UserNmFile) UserPwdFile = Server.MapPath (UserPwdFile) NmFile = Server.MapPath (NmFile) GenderFile = Server.MapPath ( GenderFile) MmFile = Server.MapPath (MmFile) '' wrote user information to a file Sub WriteUser (UserName, FileName, UserInfo) Dim fs, f Set fs = CreateObject ( "Scripting.FileSystemObject") If fs.FileExists (FileName) = False THEN FS.CREATEXTFILE (filename) Endiff's Open File SET F = fs.opentextFile (FileName, 8) 'User Information Start Sign F.Writeline ("` "& UserName &" `") F.Writeline (UserInfo ) 'User information End Sign F.Writeline ("` e` "f.close set f = nothing set fs = nothingend sub' read User Information Function Readuser (username, filename) DIM I DIM S DIM RET DIM FS, F Set fs = creteObject ("scripting.filesystemObject") if fs.fileexists (filename) = false kil FS = Nothing readuser = "" EXIT function end if 'Open files in read-only mode SET F = fs.opentextfile (filename, 1) do while f.atendofstream <> true s = f.readline if s = "` "& username & "` "THEN S = f.readline ret =" "Do while s <>" `e`" if Ret = "" "= RET S ELSE RET = RET CHR (13) & chr (10) s end if s =

F.Readline loop exit do end if loop f.close set f = nothing set fs = nothing readuser = retend function 'Delete User Information SUB Deleteuser (Username, FileName) DIM I DIM S DIM TMP DIM FS, F SET FS = CREATEOBJECT "Scripting.filesystemobject") if fs.fileexists (filename) = false the set fs = nothing exit sub end if set f = fs.opentextfile (filename, 1) TMP = "" Do while f.atendofstream <> true s = f .Readline if s <> "` "& username &" `" THEN IF TMP = "" "TMP = TMP S ELSE TMP = TMP CHR (13) & chr (10) s end if else do while s < > "` e` "s = f.readline loop end if loop f.close set f = fs.createtextfile (filename, true) f.writeLine Tmp f.close set f = nothing set fs = nothingnd sub 'modify user information SUB ModifyUser (UserName, FileName, NewUserInfo) Dim i Dim s Dim tmp Dim fs, f Set fs = CreateObject ( "Scripting.FileSystemObject") if fs.FileExists (FileName) = false then Set fs = Nothing Exit Sub end if Set f = fs.opentextfile (filename, 1) TMP = "" DO while f.atendofstream <> true s = f.readline if s <> "` "& username &" `" THEN IF TMP = "" TMP = TMP S else TMP = TMP CHR (13) & chr (10) S end if Else do while s <> "` e` "s = f.readline loop if tmp =" "THEN TMP = TMP " `" & UserName & "` "

ELSE TMP = TMP CHR (13) & chr (10) "` "& username &" `" end if TMP = TMP CHR (13) & chr (10) NewUserInfo TMP = TMP CHR (13) & CHR (10) "` e` "end if loop f.close set f = fs.createtextfile (filename, true) f.writeline tmp f.close set f = nothing set fs = nothingnd sub 'determines if the user has function UserExist (UserName, FileName) Dim fs, f Set fs = CreateObject ( "Scripting.FileSystemObject") if fs.FileExists (FileName) = False then Set fs = Nothing UserExist = False Exit Function end if Set f = fs.OpenTextFile (FileName 1) do while f.atendofstream <> true s = f.readline if s = "` "& username &" `" THENEREXIST = true exit function end if loop f.close set f = nothing set fs = Nothing userexist = Faleseend function%> '***************************************************** *************** User registration
User login
User Modification
User Delete < BR> '************** register.htm ******************** ******************** User registration

Username
Gender