Layout restriction is best done through Security > Privilege Sets > Layouts, there you can create calculations, etc. to allow or restrict the users access to same.
I agree with Bumper, but to get a script that uses re-log in to work, use this script:
Set Error Capture [on]
If [Get (LastError ) = 0 ]
Do what should happen if log in was successful here
Cancel was clicked do what you want to have happen if cancel was clicked here