4 Replies - 1875 Views - Last Post: 09 December 2009 - 12:05 PM Rate Topic: -----

#1 student23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 08-December 09

creating new user

Posted 08 December 2009 - 02:11 PM

hi

i have created a form to add a new user but i need to make sure a user type is selected. This is done by selecting a radio button. How can i do this without the person having to write his/her desired username and password again? Also i am adding these into a text file, how would i encrypt this>

Thanks

ps I have added a screenshot showing what the form will look like


Public Class FormNewUser
	Dim filename As String
	Private Sub FormNewUser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

	End Sub

	Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
		Dim username As String
		Dim password As String
		Dim usertype As Short
		Dim acceptable As Boolean
		Do Until acceptable = True
			acceptable = ok(usertype)
			If acceptable = False Then
				Me.Show()
			Else
			End If
		Loop
		username = txtnewuser.Text
		password = txtnewpassword.Text
		filename = "Users.txt"
		FileOpen(1, filename, OpenMode.Append)
		WriteLine(1, username, password, usertype)
	End Sub
	Function ok(ByVal usertype As Short)
		Dim okay As Boolean
		If rdobtnAdmin.Checked = True Then	  'Checks to see a user type has been selected
			usertype = 1
			okay = True
		ElseIf rdobtnUser.Checked = True Then
			usertype = 2
			okay = True
		Else
			MsgBox("You must select a user type!") 'Tells user to select a usertype
			okay = False
		End If
		Return okay
	End Function
End Class

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: creating new user

#2 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: creating new user

Posted 08 December 2009 - 03:24 PM

it is vb.net dude :)
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6062
  • View blog
  • Posts: 23,513
  • Joined: 23-August 08

Re: creating new user

Posted 08 December 2009 - 04:07 PM

Moved to VB.NET
Was This Post Helpful? 0
  • +
  • -

#4 student23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 08-December 09

Re: creating new user

Posted 09 December 2009 - 09:01 AM

okay ive sorted the above problem but as always a new problem occurs. Now i have a problem with actually logging in. The problems is that i am using random access files for recording usernames and passwords. But when put in a username and password, it's always denied unless the username and password i created takes up all the alllocated space. So if the password i created was unknown with a limit of 15 characters ti gets stored as unknown with 8 spaces. So when i type in the password, the program also searches for 8 spaces after. Please this problem is driving me MAD!!.

Here is the code

Public Class Login
	Dim filename As String
	Structure user
		<VBFixedString(15)> Public Username As String
		<VBFixedString(10)> Public Password As String
		<VBFixedString(1)> Public usertype As String
	End Structure
	Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
		Dim oneuser As user

		If UsernameTextBox.Text = "" And PasswordTextBox.Text <> "" Then
			MsgBox("You must enter a username")
		ElseIf UsernameTextBox.Text <> "" And PasswordTextBox.Text = "" Then
			MsgBox("You must enter a password")
		ElseIf UsernameTextBox.Text = "" And PasswordTextBox.Text = "" Then
			MsgBox(" You must enter a Username and Password")
		Else
		End If

		filename = "Users.dat"
		FileOpen(1, filename, OpenMode.Random, , , Len(oneuser))
		FileGet(1, oneuser)
		If UsernameTextBox.Text = oneuser.Username Then
		Else : MsgBox("The username or password is incorrect")
		End If

		If PasswordTextBox.Text = oneuser.Password Then
		Else : MsgBox("The username or password is incorrect")
		End If
		FileClose(1)
		mainform.show()
		Me.Hide()
	End Sub

Was This Post Helpful? 0
  • +
  • -

#5 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: creating new user

Posted 09 December 2009 - 12:05 PM

I read your first post and here is how it is supposed to be done. If you have any questions, feel free to ask. Hope this helps.

Public Class frmNewUser

	Private loginFile As String = "logins.txt"

	Private Sub btnAddUser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddUser.Click

		Dim username As String
		Dim password As String
		Dim usertype As Integer

		If InputOK() Then

			username = txtUsername.Text
			password = txtPassword.Text

			If rdbAdmin.Checked Then
				usertype = 1
			Else
				usertype = 2
			End If

			SaveUser(username, password, usertype)

		End If

	End Sub

	Private Sub SaveUser(ByVal username As String, ByVal password As String, ByVal type As Integer)

		Try
			FileOpen(1, loginFile, OpenMode.Append)
			WriteLine(1, username, password, type)
			ResetForm()
		Catch ex As Exception
			MsgBox(ex.Message)
		Finally
			FileClose(1)
		End Try

	End Sub

	Private Function InputOK() As Boolean

		If String.IsNullOrEmpty(txtUsername.Text) Then
			MsgBox("You must enter a username")
			Return False
		ElseIf String.IsNullOrEmpty(txtPassword.Text) Then
			MsgBox("You must enter a password")
			Return False
		ElseIf rdbAdmin.Checked = False And rdbUser.Checked = False Then
			MsgBox("You must select a user type")
			Return False
		End If

		Return True

	End Function

	Private Sub ResetForm()

		txtUsername.Clear()
		txtPassword.Clear()
		rdbUser.Checked = False
		rdbAdmin.Checked = False

	End Sub
End Class



For encrypting the password I think you'll fine a very good snippet here on forum. Look for MD-5 or SHA-1 encrypting algorithm.
Of course this code can still be improved, but since I don't know your programming skills, I tried to keep it simple.

This post has been edited by FlashM: 09 December 2009 - 12:20 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1