Here's a Python answer, showcasing the re.VERBOSE facility, which is very handy if you want to come back tomorrow and understand what your regex is doing.
See this for further explanation. You won't need a vine or rope to swing on. :-)
import re
match_logon = re.compile(r"""
[1-5]? # 1. start with an optional access level (a digit from 1 to 5)
[ ] # 2. followed by a space
[a-z]{3,5} # 3. then a user name consisting of between 3 and 5 small letters
\d{3,5} # 4. followed by between 3 and 5 digits
[ ]+ # 5. then one or more spaces
(\d{4,4}) # 6. and then a four digit pin number (captured for comparison)
[ ]+ # 7. then one or more spaces
\1 # 8. and the same pin again for confirmation..
$ # match end of string
""", re.VERBOSE).match
tests = [
("1 xyz123 9876 9876", True),
(" xyz123 9876 9876", True), # leading space? revisit requirement!
("0 xyz123 9876 9876", False),
("5 xyz123 9876 9876", False), # deliberate mistake to test the testing mechanism :-)
("1 xy1234 9876 9876", False),
("5 xyz123 9876 9875", False),
("1 xyz123 9876 9876\0", False),
]
for data, expected in tests:
actual = bool(match_logon(data))
print actual == expected, actual, expected, repr(data)
Results:
True True True '1 xyz123 9876 9876'
True True True ' xyz123 9876 9876'
True False False '0 xyz123 9876 9876'
False True False '5 xyz123 9876 9876'
True False False '1 xy1234 9876 9876'
True False False '5 xyz123 9876 9875'
True False False '1 xyz123 9876 9876\x00'