I have a form on my webpage (it is an asp file). Is it best practice to include the form authentication scripts (in this case username and password check) in the same file or to have it separately? My thought process is that this will happen:
- user enters data in form
- on submit data is sent to the 'authentication' asp page where script processes input
- script checks against da开发者_如何学Pythonta in file
- script page then redirects back to original page with 'login successful' or 'unsuccessful' message.
Is this along the right lines?
Personally, I'd separate them out. I find it convenient to have the authentication logic in one place, separate from other stuff, although there are many other ways to accomplish this than placing the authentication on another page. One more concrete advantage is that you could have several login forms on different pages that all submit to the authentication script, which then could redirect the user back whence they came. This may or may not be any use to you, and you could always refactor it to this approach later if you found you needed it.
You are on the right path. Yes, it would make sense to authenticate on a separate page. From my experience, it makes the single-page approach much more spaghetti-like. I've seen the single-page approach done before, and it just gets hairy.
Other things to consider may to also put useful logic in another file to be used as an INCLUDE file within the authentication handler page. Just a thought to get some code reuse.
精彩评论