SlideShare a Scribd company logo
Forms Authentication
Storing Password in web.config file
<authentication mode="Forms">
<!-- Detailed configuration options -->
<forms name="MyCookieName"
loginUrl="DbLogin.aspx"
timeout="20">
<credentials passwordFormat="Clear">
<user name="Admin" password="(Admin1)"/>
<user name="Mario" password="Szpuszta"/>
<user name="Matthew" password="MacDonald"/>
</credentials>
</forms>
</authentication>
Login code
protected void LoginAction_Click(object sender,
EventArgs e)
{
if
(FormsAuthentication.Authenticate(UsernameTe
xt.Text, PasswordText.Text))
{
FormsAuthentication.RedirectFromLoginPage(User
nameText.Text, false);
}
Authenticate Method
• Validates a user name and password against
credentials stored in the configuration file for
an application.
Hashing of Password
• Password can not be plain text.
• There are various Hashing mechanisms
supported by asp.net.
– MD5
– SHA1
HashPasswordForStoringInConfigFile
Method
• Produces a hash password suitable for storing
in a configuration file based on the specified
password and hash algorithm.
• It takes two parameters.
• The first parameter specifies the clear-text
password, and the second one specifies the
hash algorithm you should use.
Example
• string hashedPwd =
FormsAuthentication.HashPasswordForStorin
gInConfigFile(clearTextPassword, "SHA1");
• The result of the method call is the hashed
version of the password. This result needs to
be stored in the web.config
Store Hashed password in web.config
file
ConfigurationSectionGroup SystemWeb =
MyConfig.SectionGroups["system.web"];
AuthenticationSection AuthSec =
(AuthenticationSection)SystemWeb.Sections["auth
entication"];
AuthSec.Forms.Credentials.Users.Add(
new FormsAuthenticationUser(UsernameText.Text,
PasswordText.Text));
MyConfig.Save()
Cookieless Forms Authentication
• If you don’t want the runtime to use cookies,
you configure this through the cookieless
attribute of the <forms /> tag in the
<authentication /> section
Example
<authentication mode="Forms">
<!-- Detailed configuration options -->
<forms name="MyCookieName"
loginUrl="DbLogin.aspx"
cookieless=”AutoDetect” />
</authentication>
Cookiless Options
Cont
Is Web.config good place to store
credentials ?
Problems with Web.Config
• Potential lack of security.
• No support for adding user-specific
information.
• Poor performance with a large number of
users.
Persistent Cookie
• Meaning of Creating Persistent cookie is that
It will maintain user information across
various browser sessions.
• If cookie is persistent then even user closes
browser and reopens it , the session would be
running.
• Session is killed only with use of SignOut
Method.
Explicitly killing session
• Persistent cookies are not affected by the
timeout attribute that is set in the <forms>
element of the web.config file.
• If you want the persistent cookie to eventually
expire sometime in the future, you have to
use the GetAuthCookie() method of
FormsAuthentication, set the expiry date and
time
Example
Thank you

More Related Content

PPT
Session,cookies
PPSX
ASP.Net Presentation Part3
PDF
Aspnet auth advanced_cs
PPTX
Build 2016 - P508 - Customizing Your Device Experience with Assigned Access
ODP
Nosql availability & integrity
PPT
Perl Development
PPT
2310 b 11
PPTX
Java swing
Session,cookies
ASP.Net Presentation Part3
Aspnet auth advanced_cs
Build 2016 - P508 - Customizing Your Device Experience with Assigned Access
Nosql availability & integrity
Perl Development
2310 b 11
Java swing

Viewers also liked (18)

PDF
PPTX
Introduction To Silverlight and Prism
PPT
2310 b 09
PPT
01 Ajax Intro
PPT
Oid structure
PDF
5 Key Components of Genrocket
PPT
Ajax & ASP.NET 2
PPT
Oracle 10g Application Server
PDF
PPT
Itp 120 Chapt 19 2009 Binary Input & Output
PPT
jQuery introduction
PPT
Csc153 chapter 02
 
PPTX
Deploying your web application with AWS ElasticBeanstalk
PPTX
C# Delegates
PDF
Inheritance
PDF
PDF
Chapt 1 odbms
PPTX
Java 101 intro to programming with java
Introduction To Silverlight and Prism
2310 b 09
01 Ajax Intro
Oid structure
5 Key Components of Genrocket
Ajax & ASP.NET 2
Oracle 10g Application Server
Itp 120 Chapt 19 2009 Binary Input & Output
jQuery introduction
Csc153 chapter 02
 
Deploying your web application with AWS ElasticBeanstalk
C# Delegates
Inheritance
Chapt 1 odbms
Java 101 intro to programming with java
Ad

Similar to Forms authentication (20)

PPTX
PPSX
08 asp.net session11
PPS
08 asp.net session11
PPS
08 asp.net session11
PPT
Rolebased security
PPT
2310 b 16
PPT
2310 b 16
PPT
ASP.NET 13 - Security
PPTX
Security asp.net application
DOC
Tutorial asp.net
PPT
Top Ten Tips For Tenacious Defense In Asp.Net
PDF
Asp.net state management
PPTX
Formbased authentication in asp.net
PDF
C Sharp Cornerarticle
PDF
state management asp.net
PPT
State management
PPT
Session and cookies,get and post methods
PPT
State management in ASP.NET
PPT
IEEE KUET SPAC presentation
08 asp.net session11
08 asp.net session11
08 asp.net session11
Rolebased security
2310 b 16
2310 b 16
ASP.NET 13 - Security
Security asp.net application
Tutorial asp.net
Top Ten Tips For Tenacious Defense In Asp.Net
Asp.net state management
Formbased authentication in asp.net
C Sharp Cornerarticle
state management asp.net
State management
Session and cookies,get and post methods
State management in ASP.NET
IEEE KUET SPAC presentation
Ad

Recently uploaded (20)

PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
Geodesy 1.pptx...............................................
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
Digital Logic Computer Design lecture notes
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
composite construction of structures.pdf
PPTX
Welding lecture in detail for understanding
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPT
Project quality management in manufacturing
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
additive manufacturing of ss316l using mig welding
PPTX
web development for engineering and engineering
PDF
PPT on Performance Review to get promotions
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
OOP with Java - Java Introduction (Basics)
Embodied AI: Ushering in the Next Era of Intelligent Systems
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Geodesy 1.pptx...............................................
Operating System & Kernel Study Guide-1 - converted.pdf
Digital Logic Computer Design lecture notes
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
composite construction of structures.pdf
Welding lecture in detail for understanding
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Internet of Things (IOT) - A guide to understanding
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Project quality management in manufacturing
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
additive manufacturing of ss316l using mig welding
web development for engineering and engineering
PPT on Performance Review to get promotions
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
OOP with Java - Java Introduction (Basics)

Forms authentication

  • 2. Storing Password in web.config file <authentication mode="Forms"> <!-- Detailed configuration options --> <forms name="MyCookieName" loginUrl="DbLogin.aspx" timeout="20"> <credentials passwordFormat="Clear"> <user name="Admin" password="(Admin1)"/> <user name="Mario" password="Szpuszta"/> <user name="Matthew" password="MacDonald"/> </credentials> </forms> </authentication>
  • 3. Login code protected void LoginAction_Click(object sender, EventArgs e) { if (FormsAuthentication.Authenticate(UsernameTe xt.Text, PasswordText.Text)) { FormsAuthentication.RedirectFromLoginPage(User nameText.Text, false); }
  • 4. Authenticate Method • Validates a user name and password against credentials stored in the configuration file for an application.
  • 5. Hashing of Password • Password can not be plain text. • There are various Hashing mechanisms supported by asp.net. – MD5 – SHA1
  • 6. HashPasswordForStoringInConfigFile Method • Produces a hash password suitable for storing in a configuration file based on the specified password and hash algorithm. • It takes two parameters. • The first parameter specifies the clear-text password, and the second one specifies the hash algorithm you should use.
  • 7. Example • string hashedPwd = FormsAuthentication.HashPasswordForStorin gInConfigFile(clearTextPassword, "SHA1"); • The result of the method call is the hashed version of the password. This result needs to be stored in the web.config
  • 8. Store Hashed password in web.config file ConfigurationSectionGroup SystemWeb = MyConfig.SectionGroups["system.web"]; AuthenticationSection AuthSec = (AuthenticationSection)SystemWeb.Sections["auth entication"]; AuthSec.Forms.Credentials.Users.Add( new FormsAuthenticationUser(UsernameText.Text, PasswordText.Text)); MyConfig.Save()
  • 9. Cookieless Forms Authentication • If you don’t want the runtime to use cookies, you configure this through the cookieless attribute of the <forms /> tag in the <authentication /> section
  • 10. Example <authentication mode="Forms"> <!-- Detailed configuration options --> <forms name="MyCookieName" loginUrl="DbLogin.aspx" cookieless=”AutoDetect” /> </authentication>
  • 12. Cont
  • 13. Is Web.config good place to store credentials ?
  • 14. Problems with Web.Config • Potential lack of security. • No support for adding user-specific information. • Poor performance with a large number of users.
  • 15. Persistent Cookie • Meaning of Creating Persistent cookie is that It will maintain user information across various browser sessions. • If cookie is persistent then even user closes browser and reopens it , the session would be running. • Session is killed only with use of SignOut Method.
  • 16. Explicitly killing session • Persistent cookies are not affected by the timeout attribute that is set in the <forms> element of the web.config file. • If you want the persistent cookie to eventually expire sometime in the future, you have to use the GetAuthCookie() method of FormsAuthentication, set the expiry date and time