Log in Form Problem

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

32 Replies - 3157 Views - Last Post: 05 October 2010 - 10:54 PM Rate Topic: -----

#16 naveed_786  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 306
  • Joined: 13-October 09

Re: Log in Form Problem

Posted 01 September 2010 - 08:44 PM

We cann't declare two public variable togather

Public Function IsLoggedIn(ByVal PassUserName As String, ByVal PassPassword As String) As Boolean 
Public IsAdminUser As Boolean = False


It gives me error how should i declare it.
Was This Post Helpful? 0
  • +
  • -

#17 demausdauth  Icon User is online

  • D.I.C Addict
  • member icon

Reputation: 177
  • View blog
  • Posts: 647
  • Joined: 03-February 10

Re: Log in Form Problem

Posted 01 September 2010 - 09:58 PM

For the record the whole GlobalStuff Module
Module GlobalStuff
     'this is our variable that tells us whether the logged in user is
     ' an admin or not. It is available anywhere in the application.
     Public IsAdminUser As Boolean = False


     Public Function IsLoggedIn(ByVal PassUserName As String, ByVal PassPassword As String) As Boolean
          Dim ReturnBool As Boolean = True
     
          Dim cnString As String = "Data Source=ITS;Initial Catalog=Payment;Integrated Security=True"
     
          Dim conn As SqlConnection = New SqlConnection(cnString)   
          Dim sql = "SELECT Username,Pass,IsAdmin FROM Login WHERE Username = '" & PassUserName & "' AND Pass = '" & PassPassword & "'"
          Dim cmd As SqlCommand = New SqlCommand(sql, conn)
          Try
               conn.Open()
               Dim dr As SqlDataReader = cmd.ExecuteReader
          
               'ReturnBool = dr.Read()
               ' since the select statement is going to return a value that 
               ' we want to read we will go ahead and read it in
               If dr.Read() Then
                    GlobalStuff.IsAdminUser = Convert.ToBoolean(dr("IsAdmin").ToString())
               Else
                    GlobalStuff.IsAdminUser = False
                    ReturnBool = False
               End If   
          Catch Exp As SqlException
               ReturnBool = False
               'Put other code to handle, log, etc... errors here
          Catch Exp As Exception
               ReturnBool = False
               'Put other code to handle, log, etc... errors here
          Finally
               If conn IsNot Nothing AndAlso conn.State <> ConnectionState.Closed Then
                    conn.Close()
               End If          
          End Try

          Return ReturnBool

     End Function

End Module



Was This Post Helpful? 1
  • +
  • -

#18 naveed_786  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 306
  • Joined: 13-October 09

Re: Log in Form Problem

Posted 01 September 2010 - 11:30 PM

Now it gives me error when i call IsAdminUser code is given below

  Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Button2.Enabled = False
        Button4.Enabled = False
        GlobalStuff.IsAdminUser()
    End Sub


Error is "Expression is not a valid method.

This post has been edited by naveed_786: 01 September 2010 - 11:32 PM

Was This Post Helpful? 0
  • +
  • -

#19 demausdauth  Icon User is online

  • D.I.C Addict
  • member icon

Reputation: 177
  • View blog
  • Posts: 647
  • Joined: 03-February 10

Re: Log in Form Problem

Posted 01 September 2010 - 11:41 PM

It is not a method .... no parenthesis

Using your example Form2 code... let us say that Button2 should be enabled for administrators only and Button4 is for both administrators and regular users. We set the Enabled property of Button2 with the global variable GlobalStuff.IsAdminUser whereas Button4 can be used by both so we just enable it.

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      Button2.Enabled = GlobalStuff.IsAdminUser
      Button4.Enabled = True 

      Button22.Enabled = Not GlobalStuff.IsAdminUser     
  End Sub



Button22 gives an example of excluding the administrators from using that particular button.

And this can be done with any control that has .Visible or .Enabled properties.

This post has been edited by demausdauth: 01 September 2010 - 11:42 PM

Was This Post Helpful? 1
  • +
  • -

#20 motcom  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,371
  • Joined: 16-June 08

Re: Log in Form Problem

Posted 02 September 2010 - 05:03 AM

Naveed, you are trying to hard.
Maybe this project is a little bit over your head.

You should get comfortable with coding and the basics. But I mean really comfortable.

Permissions in a Project can be done in lots of ways, you need to think what access you want to give, is it on a form level, meaning certain people can access certain forms. And/Or if everyone is allowed to see everything but not allowed to either add/edit/delete etc..

Once you have that figured out, design the appropriate class to do the work for you.

People have given you examples of Modules, however try not to use Modules, you can really mess up your project with Modules and certainly if you do not know the real basics. The variables will be scoped for the entire project and if you do not treat them well and handle them well, you will have nightmares later on...

Consider building proper classes once you know exactly what kind of security you want to implement.
Was This Post Helpful? 1
  • +
  • -

#21 parbipin  Icon User is offline

  • D.I.C Head

Reputation: 29
  • View blog
  • Posts: 95
  • Joined: 23-August 10

Re: Log in Form Problem

Posted 02 September 2010 - 06:57 AM

Most of the questions asked back on these posts relate to fundamentals. I think naveed you need to first learn the difference between Modules, Functions, Variables, Subs and How they work.

If you are not able to follow completely what is being suggested then you might want to get you basics right first. demausdauth has almost given you the complete code.

demausdauth has gone a long way to help you and I do not see a single Rep for his posts. I think you might consider showing your appreciation for the efforts he has put in to help you.

Thanks
Was This Post Helpful? 0
  • +
  • -

#22 naveed_786  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 306
  • Joined: 13-October 09

Re: Log in Form Problem

Posted 05 September 2010 - 12:32 AM

Sorry i was ill now i have came back

I have apllied all the code but there are to problems.

1. I have two textboxes on my user creation form one is for username and other is password but when i try to create a user it gives me folloing error "Cann't insert null values in column 'IsAdmin' ,Table Users.dbo not allows null values insert fails.


2. Secondly It is not clear to me how i would check wether user is Admin or limited.

We have not inserted any value for IsAdmin user in the dbase.
Was This Post Helpful? 0
  • +
  • -

#23 demausdauth  Icon User is online

  • D.I.C Addict
  • member icon

Reputation: 177
  • View blog
  • Posts: 647
  • Joined: 03-February 10

Re: Log in Form Problem

Posted 07 September 2010 - 06:28 AM

1)

View Postdemausdauth, on 27 August 2010 - 01:28 PM, said:

First thing is we need to add a column to the database Login table. We'll call it IsAdmin, give a datatype of bit, do not allow null values and make it automatically default to false.


This should allow you to perform any of your Insert statements without changing them.

2) If when you are creating the users, the role of the user is not being set as it sounds in this case, then you will need a way to perform user maintenance. This will depend on your requirements but since you have 2 roles, I would assume it would be restricted to those users in the Admin role. You will have to determine whether you need another form to perform maintenance or if it can actually be done on the user creation form based on the current login (if the current login is in the Admin role then on the user creation form a checkbox will show for determining whether the new user is Admin or not). That assumes that the user creation form is available after you login.
Was This Post Helpful? 1
  • +
  • -

#24 naveed_786  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 306
  • Joined: 13-October 09

Re: Log in Form Problem

Posted 07 September 2010 - 03:01 PM

Now its working Please help me its my last question

My question is this

When i create a user and login through that user it disables the button as it was required by me its very fine problem is this how to create admin user when i login through admin every thing should be enabled.

I have putted this code on my form2 when i login from user Naveed it disables the button2

Button2.Enabled = GlobalStuff.IsAdminUser

This post has been edited by naveed_786: 07 September 2010 - 03:02 PM

Was This Post Helpful? 0
  • +
  • -

#25 demausdauth  Icon User is online

  • D.I.C Addict
  • member icon

Reputation: 177
  • View blog
  • Posts: 647
  • Joined: 03-February 10

Re: Log in Form Problem

Posted 08 September 2010 - 05:33 AM

Try putting a breakpoint on that line? Check the values of IsAdminUser? Is it what you think it should be? If not then maybe it is not being set correctly.

Place a breakpoint on the line where IsAdminUser is being set. Check out the various values like the SQL statement, does it look correct? Is the datareader .Read() branching correctly? If so then what is the value coming from the database for the column IsAdmin? Is it correct?

You may have to go back and edit the database record for the user.
Was This Post Helpful? 1
  • +
  • -

#26 naveed_786  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 306
  • Joined: 13-October 09

Re: Log in Form Problem

Posted 10 September 2010 - 02:54 AM

After debugging i obeserved this "GlobalStuff.IsAdminUser = False" i think its working very fine.

But where is admin user we have not created any admin user.

while we just have three columns in our datebase 1.UserName, 2.Pass, 3. IsAdmin

when i create any user it consider it limited user how can i create admin user.
Was This Post Helpful? 0
  • +
  • -

#27 naveed_786  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 306
  • Joined: 13-October 09

Re: Log in Form Problem

Posted 15 September 2010 - 08:06 PM

Please ans me no body has any idea????????????
Was This Post Helpful? -1
  • +
  • -

#28 demausdauth  Icon User is online

  • D.I.C Addict
  • member icon

Reputation: 177
  • View blog
  • Posts: 647
  • Joined: 03-February 10

Re: Log in Form Problem

Posted 16 September 2010 - 05:49 AM

View Postdemausdauth, on 07 September 2010 - 06:28 AM, said:

2) If when you are creating the users, the role of the user is not being set as it sounds in this case, then you will need a way to perform user maintenance. This will depend on your requirements but since you have 2 roles, I would assume it would be restricted to those users in the Admin role. You will have to determine whether you need another form to perform maintenance or if it can actually be done on the user creation form based on the current login (if the current login is in the Admin role then on the user creation form a checkbox will show for determining whether the new user is Admin or not). That assumes that the user creation form is available after you login.


You will need to directly access the database and mark at least one user as IsAdmin = true. This will also help you to check that the IsAdminUser is working correctly, otherwise it really comes down to user maintenance per your requirements.
Was This Post Helpful? 0
  • +
  • -

#29 naveed_786  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 306
  • Joined: 13-October 09

Re: Log in Form Problem

Posted 17 September 2010 - 04:44 AM

Thanks for your great help now i have made a check box please can you guide me how can i control it programaticaly thanks in advance for your help.
Was This Post Helpful? 0
  • +
  • -

#30 danny_kay1710  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 28
  • View blog
  • Posts: 358
  • Joined: 27-April 08

Re: Log in Form Problem

Posted 17 September 2010 - 05:12 AM

You need to set someone as an admin in the database have you done this?

This checkbox where have you added it - is it on a add or edit user screen?

You really need to get to terms with the basics of programming and try to understand that before attempting a project of this scale. You seem out of your depth.

You can't keep on expecting everybody else to put all of the code together and hold your hand throughout the entire project. You should be able to modify pre-existing database code to write the extra value.

Don't get me wrong everyone gets stuck but you seem to be just coming straight back to the forum rather than trying to sort it out for yourself.
Was This Post Helpful? 1
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3