Building Your First CFC: User / Method: validateUser
Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.
Learn More
Subtitles of the Movie
The last method is the function we'll use to create a secure password protected area of our site, the validate user method. This method is not different functionally from the search user method. But I separated it out so that it's easier to handle and could be called directly, if needed. The name is validate user. The hint is "Accepts user name and password and returns valid true or false". The return type is Boolean. You'll notice that we set the return type to Boolean since valid will always either be true or false. Now we'll add the arguments. The first one is user name, the type is string and it is required. The second one is password. It's also a string and it's also required. Now we'll write the query. For this query we're only going to select the columns that we need. From users where user name equals arguments dot user name and password equals arguments dot password. Next we'll set the return variable. If the query returns a record, then we'll set valid to true. If it doesn't return any records, we'll set valid to false. So if it's greater than zero, we'll set valid to true and if it's not, we'll set valid to false. We'll set the return to be the variable called valid. If valid is true, we're also going to set session variables. I'm setting session variables in this component because I know I'll be able to control where the component is called. Normally you would want to make sure you'll always have access to session management, before putting session functionality in a component. For example, if this component is called as a web service it would not work. I'm setting a lock around these session variables. I'm using a time out of 5 milliseconds. Then I'm setting session variable first name. The session variable last name and the session variable user id. And that's all that's in the validate user method. e and the session variable user id. And that's all that's in the validate user method.
Tutorial Information
| Course: | Macromedia ColdFusion MX |
| Author: | Darcey Spears |
| SKU: | 33474 |
| ISBN: | 1932072772 |
| Release Date: | 2004-03-05 |
| Duration: | 6.5 hrs / 102 lessons |
| Work Files: |
Yes |
| Captions: | For Online University members only |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 