Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default username & password check

Hi,
I have a workbook of which I have usernames (column A:A) and passwords
(column B:B) on Sheet3. I have some tables, forms etc. on Sheet1 but I want
to allow using this page to people only which can input matching
username&password with Sheet3. Can anyone suggest VBA solutions?.
TIA


  #2   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default username & password check

Hi Jack,

create a small form with 2 fields, one for the username the other for the
password.
Call it up from the ThisWorkbook.Workbook_Open event and search for the
username then match the password.

sub cmdOKButton()

with sheet3.UsedRange
CurRow=1

Do Until IsEmpty(Cells(CurRow, 1)) 'Syntax:
Cells(RowIndex,ColumnIndex)
if Cells(CurRow, 1).value=txtUserName.text then
if Cells(CurRow, 2.value=txtPassword.text then
sheets("sheet1").activate
unload me
else
msgbox "the password provided is incorrect,
please try again"
txtPassword.setfocus
end if
else ' Username not found
msgbox "I'm sorry you do seem to be a registered user,
please contact the Administrator"
unload me ' or thisworkbook.close or application.quit
end if
CurRow=CurRow+_1
Loop
end with

end sub

"Jack" wrote in message
...
Hi,
I have a workbook of which I have usernames (column A:A) and passwords
(column B:B) on Sheet3. I have some tables, forms etc. on Sheet1 but I

want
to allow using this page to people only which can input matching
username&password with Sheet3. Can anyone suggest VBA solutions?.
TIA




  #3   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default username & password check

Thank you so much for your suggestion Philo,
But I'd prefer not to use forms but just hide written data
(usernames&passwords) from Sheet3. Could you modify your code to accomplish
that.
Regards


"Philo Hippo" wrote in message
...
Hi Jack,

create a small form with 2 fields, one for the username the other for the
password.
Call it up from the ThisWorkbook.Workbook_Open event and search for the
username then match the password.

sub cmdOKButton()

with sheet3.UsedRange
CurRow=1

Do Until IsEmpty(Cells(CurRow, 1)) 'Syntax:
Cells(RowIndex,ColumnIndex)
if Cells(CurRow, 1).value=txtUserName.text then
if Cells(CurRow, 2.value=txtPassword.text then
sheets("sheet1").activate
unload me
else
msgbox "the password provided is incorrect,
please try again"
txtPassword.setfocus
end if
else ' Username not found
msgbox "I'm sorry you do seem to be a registered user,
please contact the Administrator"
unload me ' or thisworkbook.close or

application.quit
end if
CurRow=CurRow+_1
Loop
end with

end sub

"Jack" wrote in message
...
Hi,
I have a workbook of which I have usernames (column A:A) and passwords
(column B:B) on Sheet3. I have some tables, forms etc. on Sheet1 but I

want
to allow using this page to people only which can input matching
username&password with Sheet3. Can anyone suggest VBA solutions?.
TIA






  #4   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default username & password check

First, worksheet and workbook protection (via tools|protection) is very weak.
It can be broken in just moments with a macro that's readily available.

J.E. McGimpsey has code that'll unprotect your worksheet within moments:
http://www.mcgimpsey.com/excel/removepwords.html

But if you still want to try...

Rightclick on the excel icon to the left of the File option on the worksheet
menubar.

Select view code and paste this in:


Option Explicit
Const Sheet1Pwd As String = "hi"
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim resp As Long

If Me.Saved Then
'already saved
Exit Sub
End If

resp = MsgBox("Do you want to save your changes?", vbYesNoCancel, "Close")

Select Case resp
Case vbYes
Call Workbook_BeforeSave(False, False)
Case vbNo
Me.Saved = True
Case vbCancel
Cancel = True
End Select

End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

Dim Sheet1Protection As Boolean

Cancel = True 'don't let excel save it

If SaveAsUI = True Then
MsgBox "can't save this workbook as a new name!"
Exit Sub
End If

Sheet1Protection = Worksheets("sheet1").ProtectContents

If Sheet1Protection Then
'already protected
Else
Worksheets("sheet1").Protect Password:=Sheet1Pwd
End If

Application.EnableEvents = False
Me.Save
Application.EnableEvents = True

If Sheet1Protection Then
'still protected
Else
Worksheets("sheet1").Unprotect Password:=Sheet1Pwd
Me.Saved = True
End If

End Sub
Private Sub Workbook_Open()

Dim myUser As String
Dim myPwd As String
Dim myValidationRng As Range
Dim res As Variant

Worksheets("sheet1").Protect Password:=Sheet1Pwd

With Worksheets("sheet3")
Set myValidationRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))
End With

myUser = InputBox("Enter your UserName for sheet1")

If Trim(myUser) = "" Then
'do nothing
Else
res = Application.Match(myUser, myValidationRng, 0)
If IsError(res) Then
MsgBox "Not authorized"
Else
myPwd = InputBox("Enter your Password for sheet1")
If myValidationRng(res, 2).Value = myPwd Then
Worksheets("sheet1").Unprotect Password:=Sheet1Pwd
Else
MsgBox "wrong password"
End If
End If
End If

End Sub


But if the user breaks the password, disables macros, or disables events, then
lots of things could go wrong.

(I wouldn't bother with this kind of protection--it's just a false sense of
security.)



Jack wrote:

Thank you so much for your suggestion Philo,
But I'd prefer not to use forms but just hide written data
(usernames&passwords) from Sheet3. Could you modify your code to accomplish
that.
Regards

"Philo Hippo" wrote in message
...
Hi Jack,

create a small form with 2 fields, one for the username the other for the
password.
Call it up from the ThisWorkbook.Workbook_Open event and search for the
username then match the password.

sub cmdOKButton()

with sheet3.UsedRange
CurRow=1

Do Until IsEmpty(Cells(CurRow, 1)) 'Syntax:
Cells(RowIndex,ColumnIndex)
if Cells(CurRow, 1).value=txtUserName.text then
if Cells(CurRow, 2.value=txtPassword.text then
sheets("sheet1").activate
unload me
else
msgbox "the password provided is incorrect,
please try again"
txtPassword.setfocus
end if
else ' Username not found
msgbox "I'm sorry you do seem to be a registered user,
please contact the Administrator"
unload me ' or thisworkbook.close or

application.quit
end if
CurRow=CurRow+_1
Loop
end with

end sub

"Jack" wrote in message
...
Hi,
I have a workbook of which I have usernames (column A:A) and passwords
(column B:B) on Sheet3. I have some tables, forms etc. on Sheet1 but I

want
to allow using this page to people only which can input matching
username&password with Sheet3. Can anyone suggest VBA solutions?.
TIA





--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default username & password check

Thank you Dave,
I also agree your comments on security. The macro will only be used for
educational purposes....

"Dave Peterson" wrote in message
...
First, worksheet and workbook protection (via tools|protection) is very

weak.
It can be broken in just moments with a macro that's readily available.

J.E. McGimpsey has code that'll unprotect your worksheet within moments:
http://www.mcgimpsey.com/excel/removepwords.html

But if you still want to try...

Rightclick on the excel icon to the left of the File option on the

worksheet
menubar.

Select view code and paste this in:


Option Explicit
Const Sheet1Pwd As String = "hi"
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim resp As Long

If Me.Saved Then
'already saved
Exit Sub
End If

resp = MsgBox("Do you want to save your changes?", vbYesNoCancel,

"Close")

Select Case resp
Case vbYes
Call Workbook_BeforeSave(False, False)
Case vbNo
Me.Saved = True
Case vbCancel
Cancel = True
End Select

End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As

Boolean)

Dim Sheet1Protection As Boolean

Cancel = True 'don't let excel save it

If SaveAsUI = True Then
MsgBox "can't save this workbook as a new name!"
Exit Sub
End If

Sheet1Protection = Worksheets("sheet1").ProtectContents

If Sheet1Protection Then
'already protected
Else
Worksheets("sheet1").Protect Password:=Sheet1Pwd
End If

Application.EnableEvents = False
Me.Save
Application.EnableEvents = True

If Sheet1Protection Then
'still protected
Else
Worksheets("sheet1").Unprotect Password:=Sheet1Pwd
Me.Saved = True
End If

End Sub
Private Sub Workbook_Open()

Dim myUser As String
Dim myPwd As String
Dim myValidationRng As Range
Dim res As Variant

Worksheets("sheet1").Protect Password:=Sheet1Pwd

With Worksheets("sheet3")
Set myValidationRng = .Range("a1", .Cells(.Rows.Count,

"A").End(xlUp))
End With

myUser = InputBox("Enter your UserName for sheet1")

If Trim(myUser) = "" Then
'do nothing
Else
res = Application.Match(myUser, myValidationRng, 0)
If IsError(res) Then
MsgBox "Not authorized"
Else
myPwd = InputBox("Enter your Password for sheet1")
If myValidationRng(res, 2).Value = myPwd Then
Worksheets("sheet1").Unprotect Password:=Sheet1Pwd
Else
MsgBox "wrong password"
End If
End If
End If

End Sub


But if the user breaks the password, disables macros, or disables events,

then
lots of things could go wrong.

(I wouldn't bother with this kind of protection--it's just a false sense

of
security.)



Jack wrote:

Thank you so much for your suggestion Philo,
But I'd prefer not to use forms but just hide written data
(usernames&passwords) from Sheet3. Could you modify your code to

accomplish
that.
Regards

"Philo Hippo" wrote in message
...
Hi Jack,

create a small form with 2 fields, one for the username the other for

the
password.
Call it up from the ThisWorkbook.Workbook_Open event and search for

the
username then match the password.

sub cmdOKButton()

with sheet3.UsedRange
CurRow=1

Do Until IsEmpty(Cells(CurRow, 1)) 'Syntax:
Cells(RowIndex,ColumnIndex)
if Cells(CurRow, 1).value=txtUserName.text then
if Cells(CurRow, 2.value=txtPassword.text then
sheets("sheet1").activate
unload me
else
msgbox "the password provided is

incorrect,
please try again"
txtPassword.setfocus
end if
else ' Username not found
msgbox "I'm sorry you do seem to be a registered

user,
please contact the Administrator"
unload me ' or thisworkbook.close or

application.quit
end if
CurRow=CurRow+_1
Loop
end with

end sub

"Jack" wrote in message
...
Hi,
I have a workbook of which I have usernames (column A:A) and

passwords
(column B:B) on Sheet3. I have some tables, forms etc. on Sheet1 but

I
want
to allow using this page to people only which can input matching
username&password with Sheet3. Can anyone suggest VBA solutions?.
TIA





--

Dave Peterson





  #6   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default username & password check

OK but first clarify this for me please, how will you know who's who? Get
the logged on username?

"Jack" wrote in message
...
Thank you so much for your suggestion Philo,
But I'd prefer not to use forms but just hide written data
(usernames&passwords) from Sheet3. Could you modify your code to

accomplish
that.
Regards


"Philo Hippo" wrote in message
...
Hi Jack,

create a small form with 2 fields, one for the username the other for

the
password.
Call it up from the ThisWorkbook.Workbook_Open event and search for the
username then match the password.

sub cmdOKButton()

with sheet3.UsedRange
CurRow=1

Do Until IsEmpty(Cells(CurRow, 1)) 'Syntax:
Cells(RowIndex,ColumnIndex)
if Cells(CurRow, 1).value=txtUserName.text then
if Cells(CurRow, 2.value=txtPassword.text then
sheets("sheet1").activate
unload me
else
msgbox "the password provided is incorrect,
please try again"
txtPassword.setfocus
end if
else ' Username not found
msgbox "I'm sorry you do seem to be a registered

user,
please contact the Administrator"
unload me ' or thisworkbook.close or

application.quit
end if
CurRow=CurRow+_1
Loop
end with

end sub

"Jack" wrote in message
...
Hi,
I have a workbook of which I have usernames (column A:A) and passwords
(column B:B) on Sheet3. I have some tables, forms etc. on Sheet1 but I

want
to allow using this page to people only which can input matching
username&password with Sheet3. Can anyone suggest VBA solutions?.
TIA








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
link to workbook from web page asks for username and password BC Excel Discussion (Misc queries) 0 October 16th 09 03:56 PM
How do I get a adcenter username and password Chops Excel Discussion (Misc queries) 0 November 11th 08 11:31 PM
Is there a template for username and password storage for Excel? help Excel Discussion (Misc queries) 1 May 17th 05 03:29 PM
creating a username and password box kil Excel Programming 1 May 20th 04 08:20 AM
username and password for form excel vba macro finalfantasy_2u Excel Programming 0 January 9th 04 06:07 AM


All times are GMT +1. The time now is 06:26 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"