<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Savidhal</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Savidhal"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Savidhal"/>
	<updated>2026-05-10T17:23:00Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_M1502_WSRA&amp;diff=96417</id>
		<title>CSC/ECE 517 Spring 2015 M1502 WSRA</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_M1502_WSRA&amp;diff=96417"/>
		<updated>2015-04-01T18:19:41Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Design Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Implement Rust Websocket==&lt;br /&gt;
This project concentrates on implementing Rust WebSocket API for Mozilla's web browser engine, Servo&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Servo&amp;lt;ref&amp;gt; https://github.com/servo/servo &amp;lt;/ref&amp;gt; is a Web Browser engine written in [https://github.com/rust-lang/rust Rust]. It is an experimental project build that targets new generation of hardware: mobile devices, multi-core processors and high-performance GPUs to obtain power efficiency and maximum parallelism. Implementing WebSocket API for the Servo engine would allow a persistent single TCP socket connection to be established between the client and server that will provide bi-directional, full duplex, messages to be instantly exchanged with little overhead resulting in a very low latency connection and supporting interactive, dynamic applications.&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
Rust &amp;lt;ref&amp;gt; https://github.com/rust-lang/rust &amp;lt;/ref&amp;gt; is a Systems programming language built in Rust itself that is fast, memory safe and multithreaded, but does not employ a garbage collector or otherwise impose significant runtime overhead. Rust is able to provide both control over hardware and safety which is not the case with other programming languages like C, C++, Python that provide only either control or safety but not both. &lt;br /&gt;
&lt;br /&gt;
===WebSocket===&lt;br /&gt;
WebSockets is a protocol that provides [http://en.wikipedia.org/wiki/Duplex_(telecommunications)#FULL-DUPLEX full-duplex] channel for a TCP connection and makes it possible to open an interactive communication session between the user's browser and a server. With WebSockets, you can send messages to a server and receive event-driven responses without having to request the server for a reply. The [http://dev.w3.org/html5/websockets/ WebSocket] specification defines an API to establish a &amp;quot;socket&amp;quot; connection between a web browser and a server. This establishment involves a handshake following which there is a persistent connection between the client and the server and both parties can start sending data asynchronously.&lt;br /&gt;
&lt;br /&gt;
===Cargo and Crate===&lt;br /&gt;
Cargo &amp;lt;ref&amp;gt;http://doc.crates.io/guide.html&amp;lt;/ref&amp;gt; is a application level package manager that allows Rust projects to declare their various dependencies. Cargo resembles the Bundler in Rails that is used to run Rails app, install required Gems mentioned in the Gemfile. Gemfile correspond to &amp;lt;code&amp;gt; Cargo.toml &amp;lt;/code&amp;gt; file and Gem correspond to &amp;lt;code&amp;gt; Crates &amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Cargo introduces two metadata files with various bits of project information, fetches and builds project's dependencies, invokes rustc or another build tool with the correct parameters to build the project.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
==Requirement Analysis==&lt;br /&gt;
==Implementation==&lt;br /&gt;
==Architecture==&lt;br /&gt;
==Component Design==&lt;br /&gt;
==Data Design==&lt;br /&gt;
==Design Patterns==&lt;br /&gt;
&amp;lt;b&amp;gt;[http://en.wikipedia.org/wiki/Factory_%28object-oriented_programming%29 Factory Pattern]&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For every web application application running on the web browser that requires a websocket for communicating with the server, a new thread needs to be spawned that creates a client end of the socket associated with the web app. Spawning this thread can be considered to be similar to instantiating an object for which Factory Pattern can be employed. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;[http://en.wikipedia.org/wiki/Thread_pool_pattern Thread Pool Pattern]&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Servo's primary objective was to provide concurrency. This concurrency can be attained by scheduling tasks which can be run in parallel. Threads help execute these tasks in parallel. Thread Pool Pattern helps manage these thread. For example, one thread could be to accept new requests for websockets, as a result of which new thread would be spawned (client side of websocket) for that application.&lt;br /&gt;
&lt;br /&gt;
==Proposed Test Cases==&lt;br /&gt;
==Further Readings==&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_M1502_WSRA&amp;diff=96415</id>
		<title>CSC/ECE 517 Spring 2015 M1502 WSRA</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_M1502_WSRA&amp;diff=96415"/>
		<updated>2015-04-01T15:51:33Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Design Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Implement Rust Websocket==&lt;br /&gt;
This project concentrates on implementing Rust WebSocket API for Mozilla's web browser engine, Servo&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Servo&amp;lt;ref&amp;gt; https://github.com/servo/servo &amp;lt;/ref&amp;gt; is a Web Browser engine written in [https://github.com/rust-lang/rust Rust]. It is an experimental project build that targets new generation of hardware: mobile devices, multi-core processors and high-performance GPUs to obtain power efficiency and maximum parallelism. Implementing WebSocket API for the Servo engine would allow a persistent single TCP socket connection to be established between the client and server that will provide bi-directional, full duplex, messages to be instantly exchanged with little overhead resulting in a very low latency connection and supporting interactive, dynamic applications.&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
Rust &amp;lt;ref&amp;gt; https://github.com/rust-lang/rust &amp;lt;/ref&amp;gt; is a Systems programming language built in Rust itself that is fast, memory safe and multithreaded, but does not employ a garbage collector or otherwise impose significant runtime overhead. Rust is able to provide both control over hardware and safety which is not the case with other programming languages like C, C++, Python that provide only either control or safety but not both. &lt;br /&gt;
&lt;br /&gt;
===WebSocket===&lt;br /&gt;
WebSockets is a protocol that provides [http://en.wikipedia.org/wiki/Duplex_(telecommunications)#FULL-DUPLEX full-duplex] channel for a TCP connection and makes it possible to open an interactive communication session between the user's browser and a server. With WebSockets, you can send messages to a server and receive event-driven responses without having to request the server for a reply. The [http://dev.w3.org/html5/websockets/ WebSocket] specification defines an API to establish a &amp;quot;socket&amp;quot; connection between a web browser and a server. This establishment involves a handshake following which there is a persistent connection between the client and the server and both parties can start sending data asynchronously.&lt;br /&gt;
&lt;br /&gt;
===Cargo and Crate===&lt;br /&gt;
Cargo &amp;lt;ref&amp;gt;http://doc.crates.io/guide.html&amp;lt;/ref&amp;gt; is a application level package manager that allows Rust projects to declare their various dependencies. Cargo resembles the Bundler in Rails that is used to run Rails app, install required Gems mentioned in the Gemfile. Gemfile correspond to &amp;lt;code&amp;gt; Cargo.toml &amp;lt;/code&amp;gt; file and Gem correspond to &amp;lt;code&amp;gt; Crates &amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Cargo introduces two metadata files with various bits of project information, fetches and builds project's dependencies, invokes rustc or another build tool with the correct parameters to build the project.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
==Requirement Analysis==&lt;br /&gt;
==Implementation==&lt;br /&gt;
==Architecture==&lt;br /&gt;
==Component Design==&lt;br /&gt;
==Data Design==&lt;br /&gt;
==Design Patterns==&lt;br /&gt;
&amp;lt;b&amp;gt;[http://en.wikipedia.org/wiki/Factory_%28object-oriented_programming%29 Factory Pattern]&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For every web application application running on the web browser that requires a websocket for communicating with the server, a new thread needs to be spawned that creates a client end of the socket associated with the web app. Spawning this thread can be considered to be similar to instantiating an object for which Factory Pattern can be employed.&lt;br /&gt;
&lt;br /&gt;
==Proposed Test Cases==&lt;br /&gt;
==Further Readings==&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_M1502_WSRA&amp;diff=96414</id>
		<title>CSC/ECE 517 Spring 2015 M1502 WSRA</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_M1502_WSRA&amp;diff=96414"/>
		<updated>2015-04-01T15:49:36Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Design Patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Implement Rust Websocket==&lt;br /&gt;
This project concentrates on implementing Rust WebSocket API for Mozilla's web browser engine, Servo&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Servo&amp;lt;ref&amp;gt; https://github.com/servo/servo &amp;lt;/ref&amp;gt; is a Web Browser engine written in [https://github.com/rust-lang/rust Rust]. It is an experimental project build that targets new generation of hardware: mobile devices, multi-core processors and high-performance GPUs to obtain power efficiency and maximum parallelism. Implementing WebSocket API for the Servo engine would allow a persistent single TCP socket connection to be established between the client and server that will provide bi-directional, full duplex, messages to be instantly exchanged with little overhead resulting in a very low latency connection and supporting interactive, dynamic applications.&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
Rust &amp;lt;ref&amp;gt; https://github.com/rust-lang/rust &amp;lt;/ref&amp;gt; is a Systems programming language built in Rust itself that is fast, memory safe and multithreaded, but does not employ a garbage collector or otherwise impose significant runtime overhead. Rust is able to provide both control over hardware and safety which is not the case with other programming languages like C, C++, Python that provide only either control or safety but not both. &lt;br /&gt;
&lt;br /&gt;
===WebSocket===&lt;br /&gt;
WebSockets is a protocol that provides [http://en.wikipedia.org/wiki/Duplex_(telecommunications)#FULL-DUPLEX full-duplex] channel for a TCP connection and makes it possible to open an interactive communication session between the user's browser and a server. With WebSockets, you can send messages to a server and receive event-driven responses without having to request the server for a reply. The [http://dev.w3.org/html5/websockets/ WebSocket] specification defines an API to establish a &amp;quot;socket&amp;quot; connection between a web browser and a server. This establishment involves a handshake following which there is a persistent connection between the client and the server and both parties can start sending data asynchronously.&lt;br /&gt;
&lt;br /&gt;
===Cargo and Crate===&lt;br /&gt;
Cargo &amp;lt;ref&amp;gt;http://doc.crates.io/guide.html&amp;lt;/ref&amp;gt; is a application level package manager that allows Rust projects to declare their various dependencies. Cargo resembles the Bundler in Rails that is used to run Rails app, install required Gems mentioned in the Gemfile. Gemfile correspond to &amp;lt;code&amp;gt; Cargo.toml &amp;lt;/code&amp;gt; file and Gem correspond to &amp;lt;code&amp;gt; Crates &amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Cargo introduces two metadata files with various bits of project information, fetches and builds project's dependencies, invokes rustc or another build tool with the correct parameters to build the project.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
==Requirement Analysis==&lt;br /&gt;
==Implementation==&lt;br /&gt;
==Architecture==&lt;br /&gt;
==Component Design==&lt;br /&gt;
==Data Design==&lt;br /&gt;
==Design Patterns==&lt;br /&gt;
&amp;lt;b&amp;gt;[http://en.wikipedia.org/wiki/Factory_%28object-oriented_programming%29 Factory Pattern]&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
For every application requiring a websocket for communicating with the server, a new thread needs to be spawned that creates a client. Spawning this thread can be considered to be similar to instantiating an object for which Factory Pattern can be employed.&lt;br /&gt;
&lt;br /&gt;
==Proposed Test Cases==&lt;br /&gt;
==Further Readings==&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_M1502_WSRA&amp;diff=96405</id>
		<title>CSC/ECE 517 Spring 2015 M1502 WSRA</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_M1502_WSRA&amp;diff=96405"/>
		<updated>2015-04-01T06:41:18Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Implement Rust Websocket==&lt;br /&gt;
This project concentrates on implementing Rust WebSocket API for Mozilla's web browser engine, Servo&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Servo&amp;lt;ref&amp;gt; https://github.com/servo/servo &amp;lt;/ref&amp;gt; is a Web Browser engine written in [https://github.com/rust-lang/rust Rust]. It is an experimental project build that targets new generation of hardware: mobile devices, multi-core processors and high-performance GPUs to obtain power efficiency and maximum parallelism. Implementing WebSocket API for the Servo engine would allow a persistent single TCP socket connection to be established between the client and server that will provide bi-directional, full duplex, messages to be instantly exchanged with little overhead resulting in a very low latency connection and supporting interactive, dynamic applications.&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
Rust &amp;lt;ref&amp;gt; https://github.com/rust-lang/rust &amp;lt;/ref&amp;gt; is a Systems programming language built in Rust itself that is fast, memory safe and multithreaded, but does not employ a garbage collector or otherwise impose significant runtime overhead. Rust is able to provide both control over hardware and safety which is not the case with other programming languages like C, C++, Python that provide only either control or safety but not both. &lt;br /&gt;
&lt;br /&gt;
===WebSocket===&lt;br /&gt;
WebSockets is a protocol that provides [http://en.wikipedia.org/wiki/Duplex_(telecommunications)#FULL-DUPLEX full-duplex] channel for a TCP connection and makes it possible to open an interactive communication session between the user's browser and a server. With WebSockets, you can send messages to a server and receive event-driven responses without having to request the server for a reply. The [http://dev.w3.org/html5/websockets/ WebSocket] specification defines an API to establish a &amp;quot;socket&amp;quot; connection between a web browser and a server. This establishment involves a handshake following which there is a persistent connection between the client and the server and both parties can start sending data asynchronously.&lt;br /&gt;
&lt;br /&gt;
===Cargo and Crate===&lt;br /&gt;
Cargo &amp;lt;ref&amp;gt;http://doc.crates.io/guide.html&amp;lt;/ref&amp;gt; is a application level package manager that allows Rust projects to declare their various dependencies. Cargo resembles the Bundler in Rails that is used to run Rails app, install required Gems mentioned in the Gemfile. Gemfile correspond to &amp;lt;code&amp;gt; Cargo.toml &amp;lt;/code&amp;gt; file and Gem correspond to &amp;lt;code&amp;gt; Crates &amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Cargo introduces two metadata files with various bits of project information, fetches and builds project's dependencies, invokes rustc or another build tool with the correct parameters to build the project.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
==Requirement Analysis==&lt;br /&gt;
==Implementation==&lt;br /&gt;
==Architecture==&lt;br /&gt;
==Component Design==&lt;br /&gt;
==Data Design==&lt;br /&gt;
==Design Patterns==&lt;br /&gt;
==Proposed Test Cases==&lt;br /&gt;
==Further Readings==&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_M1502_WSRA&amp;diff=96404</id>
		<title>CSC/ECE 517 Spring 2015 M1502 WSRA</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_M1502_WSRA&amp;diff=96404"/>
		<updated>2015-04-01T06:40:42Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Implement Rust Websocket==&lt;br /&gt;
This project concentrates on implementing Rust WebSocket API for Mozilla's web browser engine, Servo&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Servo&amp;lt;ref&amp;gt; https://github.com/servo/servo &amp;lt;/ref&amp;gt; is a Web Browser engine written in [https://github.com/rust-lang/rust Rust]. It is an experimental project build that targets new generation of hardware: mobile devices, multi-core processors and high-performance GPUs to obtain power efficiency and maximum parallelism. Implementing WebSocket API for the Servo engine would allow a persistent single TCP socket connection to be established between the client and server that will provide bi-directional, full duplex, messages to be instantly exchanged with little overhead resulting in a very low latency connection and supporting interactive, dynamic applications.&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
Rust &amp;lt;ref&amp;gt; https://github.com/rust-lang/rust &amp;lt;/ref&amp;gt; is a Systems programming language built in Rust itself that is fast, memory safe and multithreaded, but does not employ a garbage collector or otherwise impose significant runtime overhead. Rust is able to provide both control over hardware and safety which is not the case with other programming languages like C, C++, Python that provide only either control or safety but not both. &lt;br /&gt;
&lt;br /&gt;
===WebSocket===&lt;br /&gt;
WebSockets is a protocol that provides [http://en.wikipedia.org/wiki/Duplex_(telecommunications)#FULL-DUPLEX full-duplex] channel for a TCP connection and makes it possible to open an interactive communication session between the user's browser and a server. With WebSockets, you can send messages to a server and receive event-driven responses without having to request the server for a reply. The [http://dev.w3.org/html5/websockets/ WebSocket] specification defines an API to establish a &amp;quot;socket&amp;quot; connection between a web browser and a server. This establishment involves a handshake following which there is a persistent connection between the client and the server and both parties can start sending data asynchronously.&lt;br /&gt;
&lt;br /&gt;
===Cargo and Crate===&lt;br /&gt;
Cargo &amp;lt;ref&amp;gt;http://doc.crates.io/guide.html&amp;lt;/ref&amp;gt; is a application level package manager that allows Rust projects to declare their various dependencies. Cargo resembles the Bundler in Rails that is used to run Rails app, install required Gems mentioned in the Gemfile. Gemfile correspond to &amp;lt;code&amp;gt; Cargo.toml &amp;lt;/code&amp;gt; file and Gem correspond to &amp;lt;code&amp;gt; Crates &amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Cargo introduces two metadata files with various bits of project information, fetches and builds project's dependencies, invokes rustc or another build tool with the correct parameters to build the project.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
==Requirement Analysis==&lt;br /&gt;
==Implementation==&lt;br /&gt;
==Architecture==&lt;br /&gt;
==Component Design==&lt;br /&gt;
==Data Design==&lt;br /&gt;
==Design Patterns==&lt;br /&gt;
==Proposed Test Cases==&lt;br /&gt;
==Further Readings==&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;ref /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_M1502_WSRA&amp;diff=96403</id>
		<title>CSC/ECE 517 Spring 2015 M1502 WSRA</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_M1502_WSRA&amp;diff=96403"/>
		<updated>2015-04-01T06:40:27Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Implement Rust Websocket==&lt;br /&gt;
This project concentrates on implementing Rust WebSocket API for Mozilla's web browser engine, Servo&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Servo&amp;lt;ref&amp;gt; https://github.com/servo/servo &amp;lt;/ref&amp;gt; is a Web Browser engine written in [https://github.com/rust-lang/rust Rust]. It is an experimental project build that targets new generation of hardware: mobile devices, multi-core processors and high-performance GPUs to obtain power efficiency and maximum parallelism. Implementing WebSocket API for the Servo engine would allow a persistent single TCP socket connection to be established between the client and server that will provide bi-directional, full duplex, messages to be instantly exchanged with little overhead resulting in a very low latency connection and supporting interactive, dynamic applications.&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
Rust &amp;lt;ref&amp;gt; https://github.com/rust-lang/rust &amp;lt;/ref&amp;gt; is a Systems programming language built in Rust itself that is fast, memory safe and multithreaded, but does not employ a garbage collector or otherwise impose significant runtime overhead. Rust is able to provide both control over hardware and safety which is not the case with other programming languages like C, C++, Python that provide only either control or safety but not both. &lt;br /&gt;
&lt;br /&gt;
===WebSocket===&lt;br /&gt;
WebSockets is a protocol that provides [http://en.wikipedia.org/wiki/Duplex_(telecommunications)#FULL-DUPLEX full-duplex] channel for a TCP connection and makes it possible to open an interactive communication session between the user's browser and a server. With WebSockets, you can send messages to a server and receive event-driven responses without having to request the server for a reply. The [http://dev.w3.org/html5/websockets/ WebSocket] specification defines an API to establish a &amp;quot;socket&amp;quot; connection between a web browser and a server. This establishment involves a handshake following which there is a persistent connection between the client and the server and both parties can start sending data asynchronously.&lt;br /&gt;
&lt;br /&gt;
===Cargo and Crate===&lt;br /&gt;
Cargo &amp;lt;ref&amp;gt;http://doc.crates.io/guide.html&amp;lt;/ref&amp;gt; is a application level package manager that allows Rust projects to declare their various dependencies. Cargo resembles the Bundler in Rails that is used to run Rails app, install required Gems mentioned in the Gemfile. Gemfile correspond to &amp;lt;code&amp;gt; Cargo.toml &amp;lt;/code&amp;gt; file and Gem correspond to &amp;lt;code&amp;gt; Crates &amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Cargo introduces two metadata files with various bits of project information, fetches and builds project's dependencies, invokes rustc or another build tool with the correct parameters to build the project.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
==Requirement Analysis==&lt;br /&gt;
==Implementation==&lt;br /&gt;
==Architecture==&lt;br /&gt;
==Component Design==&lt;br /&gt;
==Data Design==&lt;br /&gt;
==Design Patterns==&lt;br /&gt;
==Proposed Test Cases==&lt;br /&gt;
==Further Readings==&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_M1502_WSRA&amp;diff=96402</id>
		<title>CSC/ECE 517 Spring 2015 M1502 WSRA</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_M1502_WSRA&amp;diff=96402"/>
		<updated>2015-04-01T06:40:03Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Background */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Implement Rust Websocket==&lt;br /&gt;
This project concentrates on implementing Rust WebSocket API for Mozilla's web browser engine, Servo&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Servo&amp;lt;ref&amp;gt; https://github.com/servo/servo &amp;lt;/ref&amp;gt; is a Web Browser engine written in [https://github.com/rust-lang/rust Rust]. It is an experimental project build that targets new generation of hardware: mobile devices, multi-core processors and high-performance GPUs to obtain power efficiency and maximum parallelism. Implementing WebSocket API for the Servo engine would allow a persistent single TCP socket connection to be established between the client and server that will provide bi-directional, full duplex, messages to be instantly exchanged with little overhead resulting in a very low latency connection and supporting interactive, dynamic applications.&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
Rust &amp;lt;ref&amp;gt; https://github.com/rust-lang/rust &amp;lt;/ref&amp;gt; is a Systems programming language built in Rust itself that is fast, memory safe and multithreaded, but does not employ a garbage collector or otherwise impose significant runtime overhead. Rust is able to provide both control over hardware and safety which is not the case with other programming languages like C, C++, Python that provide only either control or safety but not both. &lt;br /&gt;
&lt;br /&gt;
===WebSocket===&lt;br /&gt;
WebSockets is a protocol that provides [http://en.wikipedia.org/wiki/Duplex_(telecommunications)#FULL-DUPLEX full-duplex] channel for a TCP connection and makes it possible to open an interactive communication session between the user's browser and a server. With WebSockets, you can send messages to a server and receive event-driven responses without having to request the server for a reply. The [http://dev.w3.org/html5/websockets/ WebSocket] specification defines an API to establish a &amp;quot;socket&amp;quot; connection between a web browser and a server. This establishment involves a handshake following which there is a persistent connection between the client and the server and both parties can start sending data asynchronously.&lt;br /&gt;
&lt;br /&gt;
===Cargo and Crate===&lt;br /&gt;
Cargo &amp;lt;ref&amp;gt;http://doc.crates.io/guide.html&amp;lt;/ref&amp;gt; is a application level package manager that allows Rust projects to declare their various dependencies. Cargo resembles the Bundler in Rails that is used to run Rails app, install required Gems mentioned in the Gemfile. Gemfile correspond to &amp;lt;code&amp;gt; Cargo.toml &amp;lt;/code&amp;gt; file and Gem correspond to &amp;lt;code&amp;gt; Crates &amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Cargo introduces two metadata files with various bits of project information, fetches and builds project's dependencies, invokes rustc or another build tool with the correct parameters to build the project.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
==Requirement Analysis==&lt;br /&gt;
==Implementation==&lt;br /&gt;
==Architecture==&lt;br /&gt;
==Component Design==&lt;br /&gt;
==Data Design==&lt;br /&gt;
==Design Patterns==&lt;br /&gt;
==Proposed Test Cases==&lt;br /&gt;
==Further Readings==&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_M1502_WSRA&amp;diff=96401</id>
		<title>CSC/ECE 517 Spring 2015 M1502 WSRA</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_M1502_WSRA&amp;diff=96401"/>
		<updated>2015-04-01T06:39:26Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Implement Rust Websocket==&lt;br /&gt;
This project concentrates on implementing Rust WebSocket API for Mozilla's web browser engine, Servo&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Servo&amp;lt;ref&amp;gt; https://github.com/servo/servo &amp;lt;/ref&amp;gt; is a Web Browser engine written in [https://github.com/rust-lang/rust Rust]. It is an experimental project build that targets new generation of hardware: mobile devices, multi-core processors and high-performance GPUs to obtain power efficiency and maximum parallelism. Implementing WebSocket API for the Servo engine would allow a persistent single TCP socket connection to be established between the client and server that will provide bi-directional, full duplex, messages to be instantly exchanged with little overhead resulting in a very low latency connection and supporting interactive, dynamic applications.&lt;br /&gt;
&lt;br /&gt;
===Rust===&lt;br /&gt;
Rust &amp;lt;ref&amp;gt; https://github.com/rust-lang/rust &amp;lt;/ref&amp;gt; is a Systems programming language built in Rust itself that is fast, memory safe and multithreaded, but does not employ a garbage collector or otherwise impose significant runtime overhead. Rust is able to provide both control over hardware and safety which is not the case with other programming languages like C, C++, Python that provide only either control or safety but not both. &lt;br /&gt;
&lt;br /&gt;
===WebSocket===&lt;br /&gt;
WebSockets is a protocol that provides [http://en.wikipedia.org/wiki/Duplex_(telecommunications)#FULL-DUPLEX full-duplex] channel for a TCP connection and makes it possible to open an interactive communication session between the user's browser and a server. With WebSockets, you can send messages to a server and receive event-driven responses without having to request the server for a reply. The [http://dev.w3.org/html5/websockets/ WebSocket] specification defines an API to establish a &amp;quot;socket&amp;quot; connection between a web browser and a server. This establishment involves a handshake following which there is a persistent connection between the client and the server and both parties can start sending data asynchronously.&lt;br /&gt;
&lt;br /&gt;
===Cargo and Crate===&lt;br /&gt;
Cargo &amp;lt;ref&amp;gt;http://doc.crates.io/guide.html&amp;lt;/ref&amp;gt; is a application level package manager that allows Rust projects to declare their various dependencies. Cargo resembles the Bundler in Rails that is used to run Rails app, install required Gems mentioned in the Gemfile. Gemfile correspond to &amp;lt;code&amp;gt; Cargo.toml &amp;lt;/code&amp;gt; file and Gem correspond to &amp;lt;code&amp;gt; Crates &amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Cargo introduces two metadata files with various bits of project information, fetches and builds project's dependencies, invokes rustc or another build tool with the correct parameters to build the project.&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
==Project Description==&lt;br /&gt;
==Requirement Analysis==&lt;br /&gt;
==Implementation==&lt;br /&gt;
==Architecture==&lt;br /&gt;
==Component Design==&lt;br /&gt;
==Data Design==&lt;br /&gt;
==Design Patterns==&lt;br /&gt;
==Proposed Test Cases==&lt;br /&gt;
==Further Readings==&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_M1502_WSRA&amp;diff=96400</id>
		<title>CSC/ECE 517 Spring 2015 M1502 WSRA</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_M1502_WSRA&amp;diff=96400"/>
		<updated>2015-04-01T06:36:16Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Implement Rust Websocket==&lt;br /&gt;
This project concentrates on implementing Rust WebSocket API for Mozilla's web browser engine, Servo&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
Servo&amp;lt;ref&amp;gt; https://github.com/servo/servo &amp;lt;/ref&amp;gt; is a Web Browser engine written in [https://github.com/rust-lang/rust Rust]. It is an experimental project build that targets new generation of hardware: mobile devices, multi-core processors and high-performance GPUs to obtain power efficiency and maximum parallelism. Implementing WebSocket API for the Servo engine would allow a persistent single TCP socket connection to be established between the client and server that will provide bi-directional, full duplex, messages to be instantly exchanged with little overhead resulting in a very low latency connection and supporting interactive, dynamic applications.&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
==Project Description==&lt;br /&gt;
==Requirement Analysis==&lt;br /&gt;
==Implementation==&lt;br /&gt;
==Architecture==&lt;br /&gt;
==Component Design==&lt;br /&gt;
==Data Design==&lt;br /&gt;
==Design Patterns==&lt;br /&gt;
==Proposed Test Cases==&lt;br /&gt;
==Further Readings==&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_M1502_WSRA&amp;diff=96399</id>
		<title>CSC/ECE 517 Spring 2015 M1502 WSRA</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015_M1502_WSRA&amp;diff=96399"/>
		<updated>2015-04-01T06:31:06Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Implement Rust Websocket */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Implement Rust Websocket==&lt;br /&gt;
This project concentrates on implementing Rust WebSocket API for Mozilla's web browser engine, Servo&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
==Background==&lt;br /&gt;
==Project Description==&lt;br /&gt;
==Requirement Analysis==&lt;br /&gt;
==Implementation==&lt;br /&gt;
==Architecture==&lt;br /&gt;
==Component Design==&lt;br /&gt;
==Data Design==&lt;br /&gt;
==Design Patterns==&lt;br /&gt;
==Proposed Test Cases==&lt;br /&gt;
==Further Readings==&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95790</id>
		<title>CSC/ECE 517 Spring 2015/oss M1502 GVJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95790"/>
		<updated>2015-03-23T21:00:41Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;br&amp;gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&lt;br /&gt;
Implementing the WebSocket API&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This project concentrates on implementing Rust WebSocket API for Mozilla's web browser engine, Servo. The project work involved making the Servo's script depend on WebSocket crate.   &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==Introduction to Mozilla Servo==&lt;br /&gt;
Servo&amp;lt;ref&amp;gt; https://github.com/servo/servo &amp;lt;/ref&amp;gt; is a Web Browser engine written in [https://github.com/rust-lang/rust Rust]. Servo is an experimental project build that targets new generation of hardware: mobile devices, multi-core processors and high-performance GPUs to obtain power efficiency and maximum parallelism.&lt;br /&gt;
&lt;br /&gt;
==Rust==&lt;br /&gt;
Rust &amp;lt;ref&amp;gt; https://github.com/rust-lang/rust &amp;lt;/ref&amp;gt; is a Systems programming language built in Rust itself that is fast, memory safe and multithreaded, but does not employ a garbage collector or otherwise impose significant runtime overhead. Rust is able to provide both control over hardware and safety which is not the case with other programming languages like C, C++, Python that provide only either control or safety but not both. &lt;br /&gt;
&lt;br /&gt;
==WebSocket==&lt;br /&gt;
WebSockets is a protocol that provides [http://en.wikipedia.org/wiki/Duplex_(telecommunications)#FULL-DUPLEX full-duplex] channel for a TCP connection and makes it possible to open an interactive communication session between the user's browser and a server. With WebSockets, you can send messages to a server and receive event-driven responses without having to request the server for a reply. The [http://dev.w3.org/html5/websockets/ WebSocket] specification defines an API to establish a &amp;quot;socket&amp;quot; connection between a web browser and a server. This establishment involves a handshake following which there is a persistent connection between the client and the server and both parties can start sending data asynchronously.&lt;br /&gt;
&lt;br /&gt;
==Cargo and Crate==&lt;br /&gt;
Cargo &amp;lt;ref&amp;gt;http://doc.crates.io/guide.html&amp;lt;/ref&amp;gt; is a application level package manager that allows Rust projects to declare their various dependencies. Cargo resembles the Bundler in Rails that is used to run Rails app, install required Gems mentioned in the Gemfile. Gemfile correspond to &amp;lt;code&amp;gt; Cargo.toml &amp;lt;/code&amp;gt; file and Gem correspond to &amp;lt;code&amp;gt; Crates &amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Cargo introduces two metadata files with various bits of project information, fetches and builds project's dependencies, invokes rustc or another build tool with the correct parameters to build the project.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
The goal of this project was to incorporate the websocket crate in to servo, using the up to date rust websocket crate instructions. To do that, Rust's crate manager and how it interacted with servo's Mach tool was explored.  &lt;br /&gt;
&lt;br /&gt;
===The Crate Manager===&lt;br /&gt;
To incorporate new crates in to a project in rust, two main tasks are needed. First, depending on the crate that is used, a dependency needs to be added to the relevant Cargo.toml. For servo and websocket, that Cargo.toml is related to the script component, found in servo's components/script folder. To add a dependency to the Cargo.toml file, a couple different methods are available, both with separate advantages. &lt;br /&gt;
&lt;br /&gt;
The first method is the simplest, and allows specification of crate versions through a method similar to Ruby gemfiles. Simply navigate to the &amp;lt;code&amp;gt;[dependencies]&amp;lt;/code&amp;gt; section of the Cargo.toml, and add the crate and the version, like this example with websocket: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[dependencies]&lt;br /&gt;
...&lt;br /&gt;
websocket = &amp;quot;0.11.0&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can vary this with other options, like ~, as in Ruby, to specify that the latest crate should be loaded or an exact version. &lt;br /&gt;
&lt;br /&gt;
The second method of adding a dependency allows for far more flexibility. A crate's git repository can be added directly to the Cargo.toml, as well as many options to use particular branches, versions, and revisions. &lt;br /&gt;
The syntax for these dependencies is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[dependency.crate_name]&lt;br /&gt;
git = &amp;quot;path_to_crate_git&amp;quot;&lt;br /&gt;
//other options&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Other options that are particularly useful include the ability to choose branches and revisions. Each of these options are shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
branch = &amp;quot;name_of_branch&amp;quot;&lt;br /&gt;
rev = &amp;quot;hash_of_commit&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The next step for adding a crate to a servo project requires modifying the main.rs or lib.rs, depending on which is being used for the project. Normally, the main.rs is used for the primary package, where other parts of a project may only use a lib.rs. To add a crate in either of these files, use the code shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
extern crate crate_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Further uses of Cargo and other syntax beyond what is discussed in this article can be found [http://doc.crates.io/guide.html here].&lt;br /&gt;
&lt;br /&gt;
===Including Rust Websocket in Servo===&lt;br /&gt;
&lt;br /&gt;
To include the Rust Websocket&amp;lt;ref&amp;gt;https://github.com/cyderize/rust-websocket&amp;lt;/ref&amp;gt; crate in to Servo, an earlier version of the crate needs to be used. This is because of hyper crate dependencies. In hyper 0.3.2, method accesses were modified. Servo runs on a precompiled version of rust, one that supports hyper 0.3.0. Because of the changes in hyper 0.3.2, an earlier version of Rust Websocket that relies on hyper 0.3.0 needed to be used. &lt;br /&gt;
&lt;br /&gt;
The files for implementing the websocket functions can be found in the webidl folder inside of components/script directory. To allow these files to be used, our project needed to make changes to servo to allow the websocket crate to be compiled. The first file change that is necessary lies in components/script/Cargo.toml. The websocket dependency of the correct version needs to be added here. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[dependencies]&lt;br /&gt;
websocket = &amp;quot;0.11.0&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second file, as described above for adding the websocket crate, is also in components/script. For this section, since the servo component is the main component, the file that needs editing is lib.rs instead of main.rs. The file is modified by adding this line with the other &amp;lt;code&amp;gt; extern &amp;lt;/code&amp;gt; lines. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
extern ...&lt;br /&gt;
extern crate websocket;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once these files have been modified, return to the base servo directory, and run &amp;lt;code&amp;gt;./mach build&amp;lt;/code&amp;gt; to compile the websocket library in to Servo.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95789</id>
		<title>CSC/ECE 517 Spring 2015/oss M1502 GVJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95789"/>
		<updated>2015-03-23T20:58:27Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Including Rust Websocket in Servo */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&lt;br /&gt;
Implementing the WebSocket API&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This project concentrates on implementing Rust WebSocket API for Mozilla's web browser engine, Servo. The project work involved making the Servo's script depend on WebSocket crate.   &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==Introduction to Mozilla Servo==&lt;br /&gt;
Servo&amp;lt;ref&amp;gt; https://github.com/servo/servo &amp;lt;/ref&amp;gt; is a Web Browser engine written in [https://github.com/rust-lang/rust Rust]. Servo is an experimental project build that targets new generation of hardware: mobile devices, multi-core processors and high-performance GPUs to obtain power efficiency and maximum parallelism.&lt;br /&gt;
&lt;br /&gt;
==Rust==&lt;br /&gt;
Rust &amp;lt;ref&amp;gt; https://github.com/rust-lang/rust &amp;lt;/ref&amp;gt; is a Systems programming language built in Rust itself that is fast, memory safe and multithreaded, but does not employ a garbage collector or otherwise impose significant runtime overhead. Rust is able to provide both control over hardware and safety which is not the case with other programming languages like C, C++, Python that provide only either control or safety but not both. &lt;br /&gt;
&lt;br /&gt;
==WebSocket==&lt;br /&gt;
WebSockets is a protocol that provides [http://en.wikipedia.org/wiki/Duplex_(telecommunications)#FULL-DUPLEX full-duplex] channel for a TCP connection and makes it possible to open an interactive communication session between the user's browser and a server. With WebSockets, you can send messages to a server and receive event-driven responses without having to request the server for a reply. The [http://dev.w3.org/html5/websockets/ WebSocket] specification defines an API to establish a &amp;quot;socket&amp;quot; connection between a web browser and a server. This establishment involves a handshake following which there is a persistent connection between the client and the server and both parties can start sending data asynchronously.&lt;br /&gt;
&lt;br /&gt;
==Cargo and Crate==&lt;br /&gt;
Cargo &amp;lt;ref&amp;gt;http://doc.crates.io/guide.html&amp;lt;/ref&amp;gt; is a application level package manager that allows Rust projects to declare their various dependencies. Cargo resembles the Bundler in Rails that is used to run Rails app, install required Gems mentioned in the Gemfile. Gemfile correspond to &amp;lt;code&amp;gt; Cargo.toml &amp;lt;/code&amp;gt; file and Gem correspond to &amp;lt;code&amp;gt; Crates &amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Cargo introduces two metadata files with various bits of project information, fetches and builds project's dependencies, invokes rustc or another build tool with the correct parameters to build the project.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
The goal of this project was to incorporate the websocket crate in to servo, using the up to date rust websocket crate instructions. To do that, Rust's crate manager and how it interacted with servo's Mach tool was explored.  &lt;br /&gt;
&lt;br /&gt;
===The Crate Manager===&lt;br /&gt;
To incorporate new crates in to a project in rust, two main tasks are needed. First, depending on the crate that is used, a dependency needs to be added to the relevant Cargo.toml. For servo and websocket, that Cargo.toml is related to the script component, found in servo's components/script folder. To add a dependency to the Cargo.toml file, a couple different methods are available, both with separate advantages. &lt;br /&gt;
&lt;br /&gt;
The first method is the simplest, and allows specification of crate versions through a method similar to Ruby gemfiles. Simply navigate to the &amp;lt;code&amp;gt;[dependencies]&amp;lt;/code&amp;gt; section of the Cargo.toml, and add the crate and the version, like this example with websocket: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[dependencies]&lt;br /&gt;
...&lt;br /&gt;
websocket = &amp;quot;0.11.0&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can vary this with other options, like ~, as in Ruby, to specify that the latest crate should be loaded or an exact version. &lt;br /&gt;
&lt;br /&gt;
The second method of adding a dependency allows for far more flexibility. A crate's git repository can be added directly to the Cargo.toml, as well as many options to use particular branches, versions, and revisions. &lt;br /&gt;
The syntax for these dependencies is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[dependency.crate_name]&lt;br /&gt;
git = &amp;quot;path_to_crate_git&amp;quot;&lt;br /&gt;
//other options&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Other options that are particularly useful include the ability to choose branches and revisions. Each of these options are shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
branch = &amp;quot;name_of_branch&amp;quot;&lt;br /&gt;
rev = &amp;quot;hash_of_commit&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The next step for adding a crate to a servo project requires modifying the main.rs or lib.rs, depending on which is being used for the project. Normally, the main.rs is used for the primary package, where other parts of a project may only use a lib.rs. To add a crate in either of these files, use the code shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
extern crate crate_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Further uses of Cargo and other syntax beyond what is discussed in this article can be found [http://doc.crates.io/guide.html here].&lt;br /&gt;
&lt;br /&gt;
===Including Rust Websocket in Servo===&lt;br /&gt;
&lt;br /&gt;
To include the Rust Websocket&amp;lt;ref&amp;gt;https://github.com/cyderize/rust-websocket&amp;lt;/ref&amp;gt; crate in to Servo, an earlier version of the crate needs to be used. This is because of hyper crate dependencies. In hyper 0.3.2, method accesses were modified. Servo runs on a precompiled version of rust, one that supports hyper 0.3.0. Because of the changes in hyper 0.3.2, an earlier version of Rust Websocket that relies on hyper 0.3.0 needed to be used. &lt;br /&gt;
&lt;br /&gt;
The files for implementing the websocket functions can be found in the webidl folder inside of components/script directory. To allow these files to be used, our project needed to make changes to servo to allow the websocket crate to be compiled. The first file change that is necessary lies in components/script/Cargo.toml. The websocket dependency of the correct version needs to be added here. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[dependencies]&lt;br /&gt;
websocket = &amp;quot;0.11.0&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second file, as described above for adding the websocket crate, is also in components/script. For this section, since the servo component is the main component, the file that needs editing is lib.rs instead of main.rs. The file is modified by adding this line with the other &amp;lt;code&amp;gt; extern &amp;lt;/code&amp;gt; lines. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
extern ...&lt;br /&gt;
extern crate websocket;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once these files have been modified, return to the base servo directory, and run &amp;lt;code&amp;gt;./mach build&amp;lt;/code&amp;gt; to compile the websocket library in to Servo.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95787</id>
		<title>CSC/ECE 517 Spring 2015/oss M1502 GVJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95787"/>
		<updated>2015-03-23T20:55:49Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Introduction to Mozilla Servo */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&lt;br /&gt;
Implementing the WebSocket API&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This project concentrates on implementing Rust WebSocket API for Mozilla's web browser engine, Servo. The project work involved making the Servo's script depend on WebSocket crate.   &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==Introduction to Mozilla Servo==&lt;br /&gt;
Servo&amp;lt;ref&amp;gt; https://github.com/servo/servo &amp;lt;/ref&amp;gt; is a Web Browser engine written in [https://github.com/rust-lang/rust Rust]. Servo is an experimental project build that targets new generation of hardware: mobile devices, multi-core processors and high-performance GPUs to obtain power efficiency and maximum parallelism.&lt;br /&gt;
&lt;br /&gt;
==Rust==&lt;br /&gt;
Rust &amp;lt;ref&amp;gt; https://github.com/rust-lang/rust &amp;lt;/ref&amp;gt; is a Systems programming language built in Rust itself that is fast, memory safe and multithreaded, but does not employ a garbage collector or otherwise impose significant runtime overhead. Rust is able to provide both control over hardware and safety which is not the case with other programming languages like C, C++, Python that provide only either control or safety but not both. &lt;br /&gt;
&lt;br /&gt;
==WebSocket==&lt;br /&gt;
WebSockets is a protocol that provides [http://en.wikipedia.org/wiki/Duplex_(telecommunications)#FULL-DUPLEX full-duplex] channel for a TCP connection and makes it possible to open an interactive communication session between the user's browser and a server. With WebSockets, you can send messages to a server and receive event-driven responses without having to request the server for a reply. The [http://dev.w3.org/html5/websockets/ WebSocket] specification defines an API to establish a &amp;quot;socket&amp;quot; connection between a web browser and a server. This establishment involves a handshake following which there is a persistent connection between the client and the server and both parties can start sending data asynchron3ously.&lt;br /&gt;
&lt;br /&gt;
==Cargo and Crate==&lt;br /&gt;
Cargo &amp;lt;ref&amp;gt;http://doc.crates.io/guide.html&amp;lt;/ref&amp;gt; is a application level package manager that allows Rust projects to declare their various dependencies. Cargo resembles the Bundler in Rails that is used to run Rails app, install required Gems mentioned in the Gemfile. Gemfile correspond to &amp;lt;code&amp;gt; Cargo.toml &amp;lt;/code&amp;gt; file and Gem correspond to &amp;lt;code&amp;gt; Crates &amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Cargo introduces two metadata files with various bits of project information, fetches and builds project's dependencies, invokes rustc or another build tool with the correct parameters to build the project.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
The goal of this project was to incorporate the websocket crate in to servo, using the up to date rust websocket crate instructions. To do that, Rust's crate manager and how it interacted with servo's Mach tool was explored.  &lt;br /&gt;
&lt;br /&gt;
===The Crate Manager===&lt;br /&gt;
To incorporate new crates in to a project in rust, two main tasks are needed. First, depending on the crate that is used, a dependency needs to be added to the relevant Cargo.toml. For servo and websocket, that Cargo.toml is related to the script component, found in servo's components/script folder. To add a dependency to the Cargo.toml file, a couple different methods are available, both with separate advantages. &lt;br /&gt;
&lt;br /&gt;
The first method is the simplest, and allows specification of crate versions through a method similar to Ruby gemfiles. Simply navigate to the &amp;lt;code&amp;gt;[dependencies]&amp;lt;/code&amp;gt; section of the Cargo.toml, and add the crate and the version, like this example with websocket: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[dependencies]&lt;br /&gt;
...&lt;br /&gt;
websocket = &amp;quot;0.11.0&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can vary this with other options, like ~, as in Ruby, to specify that the latest crate should be loaded or an exact version. &lt;br /&gt;
&lt;br /&gt;
The second method of adding a dependency allows for far more flexibility. A crate's git repository can be added directly to the Cargo.toml, as well as many options to use particular branches, versions, and revisions. &lt;br /&gt;
The syntax for these dependencies is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[dependency.crate_name]&lt;br /&gt;
git = &amp;quot;path_to_crate_git&amp;quot;&lt;br /&gt;
//other options&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Other options that are particularly useful include the ability to choose branches and revisions. Each of these options are shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
branch = &amp;quot;name_of_branch&amp;quot;&lt;br /&gt;
rev = &amp;quot;hash_of_commit&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The next step for adding a crate to a servo project requires modifying the main.rs or lib.rs, depending on which is being used for the project. Normally, the main.rs is used for the primary package, where other parts of a project may only use a lib.rs. To add a crate in either of these files, use the code shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
extern crate crate_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Further uses of Cargo and other syntax beyond what is discussed in this article can be found [http://doc.crates.io/guide.html here].&lt;br /&gt;
&lt;br /&gt;
===Including Rust Websocket in Servo===&lt;br /&gt;
&lt;br /&gt;
To include the Rust Websocket crate in to Servo, an earlier version of the crate needs to be used. This is because of hyper crate dependencies. In hyper 0.3.2, method accesses were modified. Servo runs on a precompiled version of rust, one that supports hyper 0.3.0. Because of the changes in hyper 0.3.2, an earlier version of Rust Websocket that relies on hyper 0.3.0 needed to be used. &lt;br /&gt;
&lt;br /&gt;
The files for implementing the websocket functions can be found in the webidl folder inside of components/script directory. To allow these files to be used, our project needed to make changes to servo to allow the websocket crate to be compiled. The first file change that is necessary lies in components/script/Cargo.toml. The websocket dependency of the correct version needs to be added here. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[dependencies]&lt;br /&gt;
websocket = &amp;quot;0.11.0&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second file, as described above for adding the websocket crate, is also in components/script. For this section, since the servo component is the main component, the file that needs editing is lib.rs instead of main.rs. The file is modified by adding this line with the other &amp;lt;code&amp;gt; extern &amp;lt;/code&amp;gt; lines. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
extern ...&lt;br /&gt;
extern crate websocket;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once these files have been modified, return to the base servo directory, and run &amp;lt;code&amp;gt;./mach build&amp;lt;/code&amp;gt; to compile the websocket library in to Servo.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95786</id>
		<title>CSC/ECE 517 Spring 2015/oss M1502 GVJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95786"/>
		<updated>2015-03-23T20:52:52Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Cargo and Crate */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&lt;br /&gt;
Implementing the WebSocket API&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This project concentrates on implementing Rust WebSocket API for Mozilla's web browser engine, Servo. The project work involved making the Servo's script depend on WebSocket crate.   &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==Introduction to Mozilla Servo==&lt;br /&gt;
Servo is a Web Browser engine written in [https://github.com/rust-lang/rust Rust]. Servo is an experimental project build that targets new generation of hardware: mobile devices, multi-core processors and high-performance GPUs to obtain power efficiency and maximum parallelism. &lt;br /&gt;
&lt;br /&gt;
==Rust==&lt;br /&gt;
Rust &amp;lt;ref&amp;gt; https://github.com/rust-lang/rust &amp;lt;/ref&amp;gt; is a Systems programming language built in Rust itself that is fast, memory safe and multithreaded, but does not employ a garbage collector or otherwise impose significant runtime overhead. Rust is able to provide both control over hardware and safety which is not the case with other programming languages like C, C++, Python that provide only either control or safety but not both. &lt;br /&gt;
&lt;br /&gt;
==WebSocket==&lt;br /&gt;
WebSockets is a protocol that provides [http://en.wikipedia.org/wiki/Duplex_(telecommunications)#FULL-DUPLEX full-duplex] channel for a TCP connection and makes it possible to open an interactive communication session between the user's browser and a server. With WebSockets, you can send messages to a server and receive event-driven responses without having to request the server for a reply. The [http://dev.w3.org/html5/websockets/ WebSocket] specification defines an API to establish a &amp;quot;socket&amp;quot; connection between a web browser and a server. This establishment involves a handshake following which there is a persistent connection between the client and the server and both parties can start sending data asynchron3ously.&lt;br /&gt;
&lt;br /&gt;
==Cargo and Crate==&lt;br /&gt;
Cargo &amp;lt;ref&amp;gt;http://doc.crates.io/guide.html&amp;lt;/ref&amp;gt; is a application level package manager that allows Rust projects to declare their various dependencies. Cargo resembles the Bundler in Rails that is used to run Rails app, install required Gems mentioned in the Gemfile. Gemfile correspond to &amp;lt;code&amp;gt; Cargo.toml &amp;lt;/code&amp;gt; file and Gem correspond to &amp;lt;code&amp;gt; Crates &amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Cargo introduces two metadata files with various bits of project information, fetches and builds project's dependencies, invokes rustc or another build tool with the correct parameters to build the project.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
The goal of this project was to incorporate the websocket crate in to servo, using the up to date rust websocket crate instructions. To do that, Rust's crate manager and how it interacted with servo's Mach tool was explored.  &lt;br /&gt;
&lt;br /&gt;
===The Crate Manager===&lt;br /&gt;
To incorporate new crates in to a project in rust, two main tasks are needed. First, depending on the crate that is used, a dependency needs to be added to the relevant Cargo.toml. For servo and websocket, that Cargo.toml is related to the script component, found in servo's components/script folder. To add a dependency to the Cargo.toml file, a couple different methods are available, both with separate advantages. &lt;br /&gt;
&lt;br /&gt;
The first method is the simplest, and allows specification of crate versions through a method similar to Ruby gemfiles. Simply navigate to the &amp;lt;code&amp;gt;[dependencies]&amp;lt;/code&amp;gt; section of the Cargo.toml, and add the crate and the version, like this example with websocket: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[dependencies]&lt;br /&gt;
...&lt;br /&gt;
websocket = &amp;quot;0.11.0&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can vary this with other options, like ~, as in Ruby, to specify that the latest crate should be loaded or an exact version. &lt;br /&gt;
&lt;br /&gt;
The second method of adding a dependency allows for far more flexibility. A crate's git repository can be added directly to the Cargo.toml, as well as many options to use particular branches, versions, and revisions. &lt;br /&gt;
The syntax for these dependencies is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[dependency.crate_name]&lt;br /&gt;
git = &amp;quot;path_to_crate_git&amp;quot;&lt;br /&gt;
//other options&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Other options that are particularly useful include the ability to choose branches and revisions. Each of these options are shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
branch = &amp;quot;name_of_branch&amp;quot;&lt;br /&gt;
rev = &amp;quot;hash_of_commit&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The next step for adding a crate to a servo project requires modifying the main.rs or lib.rs, depending on which is being used for the project. Normally, the main.rs is used for the primary package, where other parts of a project may only use a lib.rs. To add a crate in either of these files, use the code shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
extern crate crate_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Further uses of Cargo and other syntax beyond what is discussed in this article can be found [http://doc.crates.io/guide.html here].&lt;br /&gt;
&lt;br /&gt;
===Including Rust Websocket in Servo===&lt;br /&gt;
&lt;br /&gt;
To include the Rust Websocket crate in to Servo, an earlier version of the crate needs to be used. This is because of hyper crate dependencies. In hyper 0.3.2, method accesses were modified. Servo runs on a precompiled version of rust, one that supports hyper 0.3.0. Because of the changes in hyper 0.3.2, an earlier version of Rust Websocket that relies on hyper 0.3.0 needed to be used. &lt;br /&gt;
&lt;br /&gt;
The files for implementing the websocket functions can be found in the webidl folder inside of components/script directory. To allow these files to be used, our project needed to make changes to servo to allow the websocket crate to be compiled. The first file change that is necessary lies in components/script/Cargo.toml. The websocket dependency of the correct version needs to be added here. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[dependencies]&lt;br /&gt;
websocket = &amp;quot;0.11.0&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second file, as described above for adding the websocket crate, is also in components/script. For this section, since the servo component is the main component, the file that needs editing is lib.rs instead of main.rs. The file is modified by adding this line with the other &amp;lt;code&amp;gt; extern &amp;lt;/code&amp;gt; lines. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
extern ...&lt;br /&gt;
extern crate websocket;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once these files have been modified, return to the base servo directory, and run &amp;lt;code&amp;gt;./mach build&amp;lt;/code&amp;gt; to compile the websocket library in to Servo.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95783</id>
		<title>CSC/ECE 517 Spring 2015/oss M1502 GVJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95783"/>
		<updated>2015-03-23T20:30:48Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&lt;br /&gt;
Implementing the WebSocket API&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This project concentrates on implementing Rust WebSocket API for Mozilla's web browser engine, Servo. The project work involved making the Servo's script depend on WebSocket crate.   &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==Introduction to Mozilla Servo==&lt;br /&gt;
Servo is a Web Browser engine written in [https://github.com/rust-lang/rust Rust]. Servo is an experimental project build that targets new generation of hardware: mobile devices, multi-core processors and high-performance GPUs to obtain power efficiency and maximum parallelism. &lt;br /&gt;
&lt;br /&gt;
==Rust==&lt;br /&gt;
Rust &amp;lt;ref&amp;gt; https://github.com/rust-lang/rust &amp;lt;/ref&amp;gt; is a Systems programming language built in Rust itself that is fast, memory safe and multithreaded, but does not employ a garbage collector or otherwise impose significant runtime overhead. Rust is able to provide both control over hardware and safety which is not the case with other programming languages like C, C++, Python that provide only either control or safety but not both. &lt;br /&gt;
&lt;br /&gt;
==WebSocket==&lt;br /&gt;
WebSockets is a protocol that provides [http://en.wikipedia.org/wiki/Duplex_(telecommunications)#FULL-DUPLEX full-duplex] channel for a TCP connection and makes it possible to open an interactive communication session between the user's browser and a server. With WebSockets, you can send messages to a server and receive event-driven responses without having to request the server for a reply. The [http://dev.w3.org/html5/websockets/ WebSocket] specification defines an API to establish a &amp;quot;socket&amp;quot; connection between a web browser and a server. This establishment involves a handshake following which there is a persistent connection between the client and the server and both parties can start sending data asynchron3ously.&lt;br /&gt;
&lt;br /&gt;
==Cargo and Crate==&lt;br /&gt;
Cargo &amp;lt;ref&amp;gt;http://doc.crates.io/guide.html&amp;lt;/ref&amp;gt; is a application level package manager that allows Rust projects to declare their various dependencies. Cargo resembles the Bundler in Rails that is used to run Rails app, install required Gems mentioned in the Gemfile. Gemfile correspond to &amp;lt;code&amp;gt; Cargo.toml &amp;lt;/code&amp;gt; file and Gem correspond to &amp;lt;code&amp;gt; Crates &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
The goal of this project was to incorporate the websocket crate in to servo, using the up to date rust websocket crate instructions. To do that, Rust's crate manager and how it interacted with servo's Mach tool was explored.  &lt;br /&gt;
&lt;br /&gt;
===The Crate Manager===&lt;br /&gt;
To incorporate new crates in to a project in rust, two main tasks are needed. First, depending on the crate that is used, a dependency needs to be added to the relevant Cargo.toml. For servo and websocket, that Cargo.toml is related to the script component, found in servo's components/script folder. To add a dependency to the Cargo.toml file, a couple different methods are available, both with separate advantages. &lt;br /&gt;
&lt;br /&gt;
The first method is the simplest, and allows specification of crate versions through a method similar to Ruby gemfiles. Simply navigate to the &amp;lt;code&amp;gt;[dependencies]&amp;lt;/code&amp;gt; section of the Cargo.toml, and add the crate and the version, like this example with websocket: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[dependencies]&lt;br /&gt;
...&lt;br /&gt;
websocket = &amp;quot;0.11.0&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can vary this with other options, like ~, as in Ruby, to specify that the latest crate should be loaded or an exact version. &lt;br /&gt;
&lt;br /&gt;
The second method of adding a dependency allows for far more flexibility. A crate's git repository can be added directly to the Cargo.toml, as well as many options to use particular branches, versions, and revisions. &lt;br /&gt;
The syntax for these dependencies is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[dependency.crate_name]&lt;br /&gt;
git = &amp;quot;path_to_crate_git&amp;quot;&lt;br /&gt;
//other options&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Other options that are particularly useful include the ability to choose branches and revisions. Each of these options are shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
branch = &amp;quot;name_of_branch&amp;quot;&lt;br /&gt;
rev = &amp;quot;hash_of_commit&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The next step for adding a crate to a servo project requires modifying the main.rs or lib.rs, depending on which is being used for the project. Normally, the main.rs is used for the primary package, where other parts of a project may only use a lib.rs. To add a crate in either of these files, use the code shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
extern crate crate_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Further uses of Cargo and other syntax beyond what is discussed in this article can be found [http://doc.crates.io/guide.html here].&lt;br /&gt;
&lt;br /&gt;
===Including Rust Websocket in Servo===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95780</id>
		<title>CSC/ECE 517 Spring 2015/oss M1502 GVJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95780"/>
		<updated>2015-03-23T20:25:46Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==M1502: Implementing the WebSocket API==&lt;br /&gt;
This project concentrates on implementing Rust WebSocket API for Mozilla's web browser engine, Servo. The project work involved making the Servo's script depend on WebSocket crate.   &lt;br /&gt;
&lt;br /&gt;
==Introduction to Mozilla Servo==&lt;br /&gt;
Servo is a Web Browser engine written in [https://github.com/rust-lang/rust Rust]. Servo is an experimental project build that targets new generation of hardware: mobile devices, multi-core processors and high-performance GPUs to obtain power efficiency and maximum parallelism. &lt;br /&gt;
&lt;br /&gt;
==Rust==&lt;br /&gt;
Rust &amp;lt;ref&amp;gt; https://github.com/rust-lang/rust &amp;lt;/ref&amp;gt; is a Systems programming language built in Rust itself that is fast, memory safe and multithreaded, but does not employ a garbage collector or otherwise impose significant runtime overhead. Rust is able to provide both control over hardware and safety which is not the case with other programming languages like C, C++, Python that provide only either control or safety but not both. &lt;br /&gt;
&lt;br /&gt;
==WebSocket==&lt;br /&gt;
WebSockets is a protocol that provides [http://en.wikipedia.org/wiki/Duplex_(telecommunications)#FULL-DUPLEX full-duplex] channel for a TCP connection and makes it possible to open an interactive communication session between the user's browser and a server. With WebSockets, you can send messages to a server and receive event-driven responses without having to request the server for a reply. The [http://dev.w3.org/html5/websockets/ WebSocket] specification defines an API to establish a &amp;quot;socket&amp;quot; connection between a web browser and a server. This establishment involves a handshake following which there is a persistent connection between the client and the server and both parties can start sending data asynchronously.&lt;br /&gt;
&lt;br /&gt;
==Cargo and Crate==&lt;br /&gt;
Cargo &amp;lt;ref&amp;gt;http://doc.crates.io/guide.html&amp;lt;/ref&amp;gt; is a application level package manager that allows Rust projects to declare their various dependencies. Cargo resembles the Bundler in Rails that is used to run Rails app, install required Gems mentioned in the Gemfile. Gemfile correspond to &amp;lt;code&amp;gt; Cargo.toml &amp;lt;/code&amp;gt; file and Gem correspond to &amp;lt;code&amp;gt; Crates &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
The goal of this project was to incorporate the websocket crate in to servo, using the up to date rust websocket crate instructions. To do that, Rust's crate manager and how it interacted with servo's Mach tool was explored.  &lt;br /&gt;
&lt;br /&gt;
===The Crate Manager===&lt;br /&gt;
To incorporate new crates in to a project in rust, two main tasks are needed. First, depending on the crate that is used, a dependency needs to be added to the relevant Cargo.toml. For servo and websocket, that Cargo.toml is related to the script component, found in servo's components/script folder. To add a dependency to the Cargo.toml file, a couple different methods are available, both with separate advantages. &lt;br /&gt;
&lt;br /&gt;
The first method is the simplest, and allows specification of crate versions through a method similar to Ruby gemfiles. Simply navigate to the &amp;lt;code&amp;gt;[dependencies]&amp;lt;/code&amp;gt; section of the Cargo.toml, and add the crate and the version, like this example with websocket: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[dependencies]&lt;br /&gt;
...&lt;br /&gt;
websocket = &amp;quot;0.11.0&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can vary this with other options, like ~, as in Ruby, to specify that the latest crate should be loaded or an exact version. &lt;br /&gt;
&lt;br /&gt;
The second method of adding a dependency allows for far more flexibility. A crate's git repository can be added directly to the Cargo.toml, as well as many options to use particular branches, versions, and revisions. &lt;br /&gt;
The syntax for these dependencies is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[dependency.crate_name]&lt;br /&gt;
git = &amp;quot;path_to_crate_git&amp;quot;&lt;br /&gt;
//other options&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Other options that are particularly useful include the ability to choose branches and revisions. Each of these options are shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
branch = &amp;quot;name_of_branch&amp;quot;&lt;br /&gt;
rev = &amp;quot;hash_of_commit&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The next step for adding a crate to a servo project requires modifying the main.rs or lib.rs, depending on which is being used for the project. Normally, the main.rs is used for the primary package, where other parts of a project may only use a lib.rs. To add a crate in either of these files, use the code shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
extern crate crate_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Further uses of Cargo and other syntax beyond what is discussed in this article can be found [http://doc.crates.io/guide.html here].&lt;br /&gt;
&lt;br /&gt;
===Including Rust Websocket in Servo===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95779</id>
		<title>CSC/ECE 517 Spring 2015/oss M1502 GVJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95779"/>
		<updated>2015-03-23T20:22:38Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==M1502: Implementing the WebSocket API==&lt;br /&gt;
This project concentrates on implementing Rust WebSocket API for Mozilla's web browser engine, Servo. The project work involved making the Servo's script depend on WebSocket crate.   &lt;br /&gt;
&lt;br /&gt;
==Introduction to Mozilla Servo==&lt;br /&gt;
Servo is a Web Browser engine written in [https://github.com/rust-lang/rust Rust]. Servo is an experimental project build that targets new generation of hardware: mobile devices, multi-core processors and high-performance GPUs to obtain power efficiency and maximum parallelism. &lt;br /&gt;
&lt;br /&gt;
==Rust==&lt;br /&gt;
Rust &amp;lt;ref&amp;gt; https://github.com/rust-lang/rust &amp;lt;/ref&amp;gt; is a Systems programming language built in Rust itself that is fast, memory safe and multithreaded, but does not employ a garbage collector or otherwise impose significant runtime overhead. Rust is able to provide both control over hardware and safety which is not the case with other programming languages like C, C++, Python that provide only either control or safety but not both. &lt;br /&gt;
&lt;br /&gt;
==WebSocket==&lt;br /&gt;
WebSockets is a protocol that provides [http://en.wikipedia.org/wiki/Duplex_(telecommunications)#FULL-DUPLEX full-duplex] channel for a TCP connection and makes it possible to open an interactive communication session between the user's browser and a server. With WebSockets, you can send messages to a server and receive event-driven responses without having to request the server for a reply. The [http://dev.w3.org/html5/websockets/ WebSocket] specification defines an API to establish a &amp;quot;socket&amp;quot; connection between a web browser and a server. This establishment involves a handshake following which there is a persistent connection between the client and the server and both parties can start sending data asynchronously.&lt;br /&gt;
&lt;br /&gt;
==Cargo and Crate==&lt;br /&gt;
Cargo &amp;lt;ref&amp;gt;http://doc.crates.io/guide.html&amp;lt;/ref&amp;gt; is a application level package manager that allows Rust projects to declare their various dependencies. Cargo resembles the Bundler in Rails that is used to run Rails app, install required Gems mentioned in the Gemfile. Gemfile correspond to &amp;lt;code&amp;gt; Cargo.toml &amp;lt;/code&amp;gt; file and Gem correspond to &amp;lt;code&amp;gt; Crates &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
The goal of this project was to incorporate the websocket crate in to servo, using the up to date rust websocket crate instructions. To do that, Rust's crate manager and how it interacted with servo's Mach tool was explored.  &lt;br /&gt;
&lt;br /&gt;
===The Crate Manager===&lt;br /&gt;
To incorporate new crates in to a project in rust, two main tasks are needed. First, depending on the crate that is used, a dependency needs to be added to the relevant Cargo.toml. For servo and websocket, that Cargo.toml is related to the script component, found in servo's components/script folder. To add a dependency to the Cargo.toml file, a couple different methods are available, both with separate advantages. &lt;br /&gt;
&lt;br /&gt;
The first method is the simplest, and allows specification of crate versions through a method similar to Ruby gemfiles. Simply navigate to the &amp;lt;code&amp;gt;[dependencies]&amp;lt;/code&amp;gt; section of the Cargo.toml, and add the crate and the version, like this example with websocket: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[dependencies]&lt;br /&gt;
...&lt;br /&gt;
websocket = &amp;quot;0.11.0&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can vary this with other options, like ~, as in Ruby, to specify that the latest crate should be loaded or an exact version. &lt;br /&gt;
&lt;br /&gt;
The second method of adding a dependency allows for far more flexibility. A crate's git repository can be added directly to the Cargo.toml, as well as many options to use particular branches, versions, and revisions. &lt;br /&gt;
The syntax for these dependencies is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[dependency.crate_name]&lt;br /&gt;
git = &amp;quot;path_to_crate_git&amp;quot;&lt;br /&gt;
//other options&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Other options that are particularly useful include the ability to choose branches and revisions. Each of these options are shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
branch = &amp;quot;name_of_branch&amp;quot;&lt;br /&gt;
rev = &amp;quot;hash_of_commit&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The next step for adding a crate to a servo project requires modifying the main.rs or lib.rs, depending on which is being used for the project. Normally, the main.rs is used for the primary package, where other parts of a project may only use a lib.rs. To add a crate in either of these files, use the code shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
extern crate crate_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Further uses of Cargo and other syntax beyond what is discussed in this article can be found here: [http://doc.crates.io/guide.html].&lt;br /&gt;
&lt;br /&gt;
===Including Rust Websocket in Servo===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95777</id>
		<title>CSC/ECE 517 Spring 2015/oss M1502 GVJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95777"/>
		<updated>2015-03-23T20:21:32Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Cargo and Crate */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==M1502: Implementing the WebSocket API==&lt;br /&gt;
This project concentrates on implementing Rust WebSocket API for Mozilla's web browser engine, Servo. The project work involved making the Servo's script depend on WebSocket crate.   &lt;br /&gt;
&lt;br /&gt;
==Introduction to Mozilla Servo==&lt;br /&gt;
Servo is a Web Browser engine written in [https://github.com/rust-lang/rust Rust]. Servo is an experimental project build that targets new generation of hardware: mobile devices, multi-core processors and high-performance GPUs to obtain power efficiency and maximum parallelism. &lt;br /&gt;
&lt;br /&gt;
==Rust==&lt;br /&gt;
Rust &amp;lt;ref&amp;gt; https://github.com/rust-lang/rust &amp;lt;/ref&amp;gt; is a Systems programming language built in Rust itself that is fast, memory safe and multithreaded, but does not employ a garbage collector or otherwise impose significant runtime overhead. Rust is able to provide both control over hardware and safety which is not the case with other programming languages like C, C++, Python that provide only either control or safety but not both. &lt;br /&gt;
&lt;br /&gt;
==WebSocket==&lt;br /&gt;
WebSockets is a protocol that provides [http://en.wikipedia.org/wiki/Duplex_(telecommunications)#FULL-DUPLEX full-duplex] channel for a TCP connection and makes it possible to open an interactive communication session between the user's browser and a server. With WebSockets, you can send messages to a server and receive event-driven responses without having to request the server for a reply. The [http://dev.w3.org/html5/websockets/ WebSocket] specification defines an API to establish a &amp;quot;socket&amp;quot; connection between a web browser and a server. This establishment involves a handshake following which there is a persistent connection between the client and the server and both parties can start sending data asynchronously.&lt;br /&gt;
&lt;br /&gt;
==Cargo and Crate==&lt;br /&gt;
Cargo &amp;lt;ref&amp;gt;http://doc.crates.io/guide.html&amp;lt;/ref&amp;gt; is a application level package manager that allows Rust projects to declare their various dependencies. Cargo resembles the Bundler in Rails that is used to run Rails app, install required Gems mentioned in the Gemfile. Gemfile correspond to &amp;lt;code&amp;gt; Cargo.toml &amp;lt;/code&amp;gt; file and Gem correspond to &amp;lt;code&amp;gt; Crates &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
The goal of this project was to incorporate the websocket crate in to servo, using the up to date rust websocket crate instructions. To do that, Rust's crate manager and how it interacted with servo's Mach tool was explored.  &lt;br /&gt;
&lt;br /&gt;
===The Crate Manager===&lt;br /&gt;
To incorporate new crates in to a project in rust, two main tasks are needed. First, depending on the crate that is used, a dependency needs to be added to the relevant Cargo.toml. For servo and websocket, that Cargo.toml is related to the script component, found in servo's components/script folder. To add a dependency to the Cargo.toml file, a couple different methods are available, both with separate advantages. &lt;br /&gt;
&lt;br /&gt;
The first method is the simplest, and allows specification of crate versions through a method similar to Ruby gemfiles. Simply navigate to the &amp;lt;code&amp;gt;[dependencies]&amp;lt;/code&amp;gt; section of the Cargo.toml, and add the crate and the version, like this example with websocket: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[dependencies]&lt;br /&gt;
...&lt;br /&gt;
websocket = &amp;quot;0.11.0&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can vary this with other options, like ~, as in Ruby, to specify that the latest crate should be loaded or an exact version. &lt;br /&gt;
&lt;br /&gt;
The second method of adding a dependency allows for far more flexibility. A crate's git repository can be added directly to the Cargo.toml, as well as many options to use particular branches, versions, and revisions. &lt;br /&gt;
The syntax for these dependencies is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[dependency.crate_name]&lt;br /&gt;
git = &amp;quot;path_to_crate_git&amp;quot;&lt;br /&gt;
//other options&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Other options that are particularly useful include the ability to choose branches and revisions. Each of these options are shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
branch = &amp;quot;name_of_branch&amp;quot;&lt;br /&gt;
rev = &amp;quot;hash_of_commit&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The next step for adding a crate to a servo project requires modifying the main.rs or lib.rs, depending on which is being used for the project. Normally, the main.rs is used for the primary package, where other parts of a project may only use a lib.rs. To add a crate in either of these files, use the code shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
extern crate crate_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Further uses of Cargo and other syntax beyond what is discussed in this article can be found here: [http://doc.crates.io/guide.html].&lt;br /&gt;
&lt;br /&gt;
===Including Rust Websocket in Servo===&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95776</id>
		<title>CSC/ECE 517 Spring 2015/oss M1502 GVJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95776"/>
		<updated>2015-03-23T20:20:26Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==M1502: Implementing the WebSocket API==&lt;br /&gt;
This project concentrates on implementing Rust WebSocket API for Mozilla's web browser engine, Servo. The project work involved making the Servo's script depend on WebSocket crate.   &lt;br /&gt;
&lt;br /&gt;
==Introduction to Mozilla Servo==&lt;br /&gt;
Servo is a Web Browser engine written in [https://github.com/rust-lang/rust Rust]. Servo is an experimental project build that targets new generation of hardware: mobile devices, multi-core processors and high-performance GPUs to obtain power efficiency and maximum parallelism. &lt;br /&gt;
&lt;br /&gt;
==Rust==&lt;br /&gt;
Rust &amp;lt;ref&amp;gt; https://github.com/rust-lang/rust &amp;lt;/ref&amp;gt; is a Systems programming language built in Rust itself that is fast, memory safe and multithreaded, but does not employ a garbage collector or otherwise impose significant runtime overhead. Rust is able to provide both control over hardware and safety which is not the case with other programming languages like C, C++, Python that provide only either control or safety but not both. &lt;br /&gt;
&lt;br /&gt;
==WebSocket==&lt;br /&gt;
WebSockets is a protocol that provides [http://en.wikipedia.org/wiki/Duplex_(telecommunications)#FULL-DUPLEX full-duplex] channel for a TCP connection and makes it possible to open an interactive communication session between the user's browser and a server. With WebSockets, you can send messages to a server and receive event-driven responses without having to request the server for a reply. The [http://dev.w3.org/html5/websockets/ WebSocket] specification defines an API to establish a &amp;quot;socket&amp;quot; connection between a web browser and a server. This establishment involves a handshake following which there is a persistent connection between the client and the server and both parties can start sending data asynchronously.&lt;br /&gt;
&lt;br /&gt;
==Cargo and Crate==&lt;br /&gt;
Cargo &amp;lt;ref&amp;gt;http://doc.crates.io/guide.html&amp;lt;/ref&amp;gt; is a application level package manager that allows Rust projects to declare their various dependencies. Cargo resembles the Bundler in Rails that is used to run Rails app, install required Gems mentioned in the Gemfile. Gemfile correspond to &amp;lt;code&amp;gt; Cargo.toml &amp;lt;/code&amp;gt; file and Gem correspond to &amp;lt;code&amp;gt; Crates &amp;lt;/crate&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
==Project Description==&lt;br /&gt;
The goal of this project was to incorporate the websocket crate in to servo, using the up to date rust websocket crate instructions. To do that, Rust's crate manager and how it interacted with servo's Mach tool was explored.  &lt;br /&gt;
&lt;br /&gt;
===The Crate Manager===&lt;br /&gt;
To incorporate new crates in to a project in rust, two main tasks are needed. First, depending on the crate that is used, a dependency needs to be added to the relevant Cargo.toml. For servo and websocket, that Cargo.toml is related to the script component, found in servo's components/script folder. To add a dependency to the Cargo.toml file, a couple different methods are available, both with separate advantages. &lt;br /&gt;
&lt;br /&gt;
The first method is the simplest, and allows specification of crate versions through a method similar to Ruby gemfiles. Simply navigate to the &amp;lt;code&amp;gt;[dependencies]&amp;lt;/code&amp;gt; section of the Cargo.toml, and add the crate and the version, like this example with websocket: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[dependencies]&lt;br /&gt;
...&lt;br /&gt;
websocket = &amp;quot;0.11.0&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can vary this with other options, like ~, as in Ruby, to specify that the latest crate should be loaded or an exact version. &lt;br /&gt;
&lt;br /&gt;
The second method of adding a dependency allows for far more flexibility. A crate's git repository can be added directly to the Cargo.toml, as well as many options to use particular branches, versions, and revisions. &lt;br /&gt;
The syntax for these dependencies is shown below. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[dependency.crate_name]&lt;br /&gt;
git = &amp;quot;path_to_crate_git&amp;quot;&lt;br /&gt;
//other options&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Other options that are particularly useful include the ability to choose branches and revisions. Each of these options are shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
branch = &amp;quot;name_of_branch&amp;quot;&lt;br /&gt;
rev = &amp;quot;hash_of_commit&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The next step for adding a crate to a servo project requires modifying the main.rs or lib.rs, depending on which is being used for the project. Normally, the main.rs is used for the primary package, where other parts of a project may only use a lib.rs. To add a crate in either of these files, use the code shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
extern crate crate_name&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Further uses of Cargo and other syntax beyond what is discussed in this article can be found here: [http://doc.crates.io/guide.html].&lt;br /&gt;
&lt;br /&gt;
===Including Rust Websocket in Servo===&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95770</id>
		<title>CSC/ECE 517 Spring 2015/oss M1502 GVJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95770"/>
		<updated>2015-03-23T20:07:03Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==M1502: Implementing the WebSocket API==&lt;br /&gt;
This project concentrates on implementing Rust WebSocket API for Mozilla's web browser engine, Servo. The project work involved making the Servo's script depend on WebSocket crate.   &lt;br /&gt;
&lt;br /&gt;
==Introduction to Mozilla Servo==&lt;br /&gt;
Servo is a Web Browser engine written in [https://github.com/rust-lang/rust Rust]. Servo is an experimental project build that targets new generation of hardware: mobile devices, multi-core processors and high-performance GPUs to obtain power efficiency and maximum parallelism. &lt;br /&gt;
&lt;br /&gt;
==Rust==&lt;br /&gt;
[https://github.com/rust-lang/rust Rust] is a Systems programming language built in Rust itself that is fast, memory safe and multithreaded, but does not employ a garbage collector or otherwise impose significant runtime overhead. Rust is able to provide both control over hardware and safety which is not the case with other programming languages like C, C++, Python that provide only either control or safety but not both. &lt;br /&gt;
&lt;br /&gt;
==WebSocket==&lt;br /&gt;
WebSockets is a protocol that provides [http://en.wikipedia.org/wiki/Duplex_(telecommunications)#FULL-DUPLEX full-duplex] channel for a TCP connection and makes it possible to open an interactive communication session between the user's browser and a server. With WebSockets, you can send messages to a server and receive event-driven responses without having to request the server for a reply. The [http://dev.w3.org/html5/websockets/ WebSocket] specification defines an API to establish a &amp;quot;socket&amp;quot; connection between a web browser and a server. This establishment involves a handshake following which there is a persistent connection between the client and the server and both parties can start sending data asynchronously.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
The goal of this project was to incorporate the websocket crate in to servo, using the up to date rust websocket crate instructions. To do that, Rust's crate manager and how it interacted with servo's Mach tool was explored.  &lt;br /&gt;
&lt;br /&gt;
===The Crate Manager===&lt;br /&gt;
To incorporate new crates in to a project in rust, two main tasks are needed. First, depending on the crate that is used, a dependency needs to be added to the relevant Cargo.toml. For servo and websocket, that Cargo.toml is related to the script component, found in servo's components/script folder. To add a dependency to the Cargo.toml file, a couple different methods are available, both with separate advantages. &lt;br /&gt;
&lt;br /&gt;
The first method is the simplest, and allows specification of crate versions through a method similar to Ruby gemfiles. Simply navigate to the &amp;lt;code&amp;gt;[dependencies]&amp;lt;/code&amp;gt; section of the Cargo.toml, and add the crate and the version, like this example with websocket: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[dependencies] &lt;br /&gt;
... &lt;br /&gt;
websocket = &amp;quot;0.11.3&amp;quot;  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95769</id>
		<title>CSC/ECE 517 Spring 2015/oss M1502 GVJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95769"/>
		<updated>2015-03-23T19:57:36Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* WebSocket */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==M1502: Implementing the WebSocket API==&lt;br /&gt;
This project concentrates on implementing Rust WebSocket API for Mozilla's web browser engine, Servo. The project work involved making the Servo's script depend on WebSocket crate.   &lt;br /&gt;
&lt;br /&gt;
==Introduction to Mozilla Servo==&lt;br /&gt;
Servo is a Web Browser engine written in [https://github.com/rust-lang/rust Rust]. Servo is an experimental project build that targets new generation of hardware: mobile devices, multi-core processors and high-performance GPUs to obtain power efficiency and maximum parallelism. &lt;br /&gt;
&lt;br /&gt;
==Rust==&lt;br /&gt;
[https://github.com/rust-lang/rust Rust] is a Systems programming language built in Rust itself that is fast, memory safe and multithreaded, but does not employ a garbage collector or otherwise impose significant runtime overhead. Rust is able to provide both control over hardware and safety which is not the case with other programming languages like C, C++, Python that provide only either control or safety but not both. &lt;br /&gt;
&lt;br /&gt;
==WebSocket==&lt;br /&gt;
WebSockets is a protocol that provides [http://en.wikipedia.org/wiki/Duplex_(telecommunications)#FULL-DUPLEX full-duplex] channel for a TCP connection and makes it possible to open an interactive communication session between the user's browser and a server. With WebSockets, you can send messages to a server and receive event-driven responses without having to request the server for a reply. The [http://dev.w3.org/html5/websockets/ WebSocket] specification defines an API to establish a &amp;quot;socket&amp;quot; connection between a web browser and a server. This establishment involves a handshake following which there is a persistent connection between the client and the server and both parties can start sending data asynchronously.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
The goal of this project was to incorporate the websocket crate in to servo, using the up to date rust websocket crate instructions. To do that, Rust's crate manager and how it interacted with servo's Mach tool was explored. &lt;br /&gt;
&lt;br /&gt;
===The Crate Manager===&lt;br /&gt;
To incorporate new crates in to a project in rust, two main tasks are needed. First, depending on the crate that is used, a dependency needs to be added to the relevant Cargo.toml. For servo and websocket, that Cargo.toml is related to the script component, found in servo's components/script folder. To add a dependency to the Cargo.toml file, a couple different methods are available, both with separate advantages. &lt;br /&gt;
&lt;br /&gt;
The first method is the simplest, and allows specification of crate versions through a method similar to Ruby gemfiles. Simply navigate to the &amp;lt;code&amp;gt;[dependencies]&amp;lt;/code&amp;gt; section of the Cargo.toml, and add the crate and the version, like this example with websocket: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
[dependencies] &amp;lt;br&amp;gt;&lt;br /&gt;
... &amp;lt;br&amp;gt;&lt;br /&gt;
websocket = &amp;quot;0.11.3&amp;quot; &amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95768</id>
		<title>CSC/ECE 517 Spring 2015/oss M1502 GVJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95768"/>
		<updated>2015-03-23T19:56:43Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==M1502: Implementing the WebSocket API==&lt;br /&gt;
This project concentrates on implementing Rust WebSocket API for Mozilla's web browser engine, Servo. The project work involved making the Servo's script depend on WebSocket crate.   &lt;br /&gt;
&lt;br /&gt;
==Introduction to Mozilla Servo==&lt;br /&gt;
Servo is a Web Browser engine written in [https://github.com/rust-lang/rust Rust]. Servo is an experimental project build that targets new generation of hardware: mobile devices, multi-core processors and high-performance GPUs to obtain power efficiency and maximum parallelism. &lt;br /&gt;
&lt;br /&gt;
==Rust==&lt;br /&gt;
[https://github.com/rust-lang/rust Rust] is a Systems programming language built in Rust itself that is fast, memory safe and multithreaded, but does not employ a garbage collector or otherwise impose significant runtime overhead. Rust is able to provide both control over hardware and safety which is not the case with other programming languages like C, C++, Python that provide only either control or safety but not both. &lt;br /&gt;
&lt;br /&gt;
==WebSocket==&lt;br /&gt;
WebSockets is a protocol that provides [http://en.wikipedia.org/wiki/Duplex_(telecommunications)#FULL-DUPLEX full-duplex] channel for a TCP connection and makes it possible to open an interactive communication session between the user's browser and a server. With WebSockets, you can send messages to a server and receive event-driven responses without having to request the server for a reply. The [http://dev.w3.org/html5/websockets/ WebSocket] specification defines an API to establishing a &amp;quot;socket&amp;quot; connection between a web browser and a server. This establishment involves a handhsake following which there is a persistent connection between the client and the server and both parties can start sending data asynchronously.&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;br /&gt;
The goal of this project was to incorporate the websocket crate in to servo, using the up to date rust websocket crate instructions. To do that, Rust's crate manager and how it interacted with servo's Mach tool was explored. &lt;br /&gt;
&lt;br /&gt;
===The Crate Manager===&lt;br /&gt;
To incorporate new crates in to a project in rust, two main tasks are needed. First, depending on the crate that is used, a dependency needs to be added to the relevant Cargo.toml. For servo and websocket, that Cargo.toml is related to the script component, found in servo's components/script folder. To add a dependency to the Cargo.toml file, a couple different methods are available, both with separate advantages. &lt;br /&gt;
&lt;br /&gt;
The first method is the simplest, and allows specification of crate versions through a method similar to Ruby gemfiles. Simply navigate to the &amp;lt;code&amp;gt;[dependencies]&amp;lt;/code&amp;gt; section of the Cargo.toml, and add the crate and the version, like this example with websocket: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
[dependencies] &amp;lt;br&amp;gt;&lt;br /&gt;
... &amp;lt;br&amp;gt;&lt;br /&gt;
websocket = &amp;quot;0.11.3&amp;quot; &amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95461</id>
		<title>CSC/ECE 517 Spring 2015/oss M1502 GVJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95461"/>
		<updated>2015-03-22T19:58:29Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==M1502: Implementing the WebSocket API==&lt;br /&gt;
This project concentrates on implementing Rust WebSocket API for Mozilla's web browser engine, Servo. The project work involved making the Servo's script depend on WebSocket crate.   &lt;br /&gt;
&lt;br /&gt;
==Introduction to Mozilla Servo==&lt;br /&gt;
Servo is a Web Browser engine written in [https://github.com/rust-lang/rust Rust]. Servo is an experimental project build that targets new generation of hardware: mobile devices, multi-core processors and high-performance GPUs to obtain power efficiency and maximum parallelism. &lt;br /&gt;
&lt;br /&gt;
==Rust==&lt;br /&gt;
[https://github.com/rust-lang/rust Rust] is a Systems programming language built in Rust itself that is fast, memory safe and multithreaded, but does not employ a garbage collector or otherwise impose significant runtime overhead. Rust is able to provide both control over hardware and safety which is not the case with other programming languages like C, C++, Python that provide only either control or safety but not both. &lt;br /&gt;
&lt;br /&gt;
==WebSocket==&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95460</id>
		<title>CSC/ECE 517 Spring 2015/oss M1502 GVJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95460"/>
		<updated>2015-03-22T19:19:53Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==M1502: Implementing the WebSocket API==&lt;br /&gt;
This project concentrates on implementing Rust WebSocket API for Mozilla's web browser engine, Servo. The project work involved making the Servo's script depend on WebSocket crate.   &lt;br /&gt;
&lt;br /&gt;
==Introduction to Mozilla Servo==&lt;br /&gt;
Servo is a Web Browser engine written in [https://github.com/rust-lang/rust Rust]. Servo is an experimental project build that targets new generation of hardware: mobile devices, multi-core processors and high-performance GPUs to obtain power efficiency and maximum parallelism. &lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95302</id>
		<title>CSC/ECE 517 Spring 2015/oss M1502 GVJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95302"/>
		<updated>2015-03-22T01:27:20Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==M1502: Implementing the WebSocket API==&lt;br /&gt;
This project concentrates on implementing Rust WebSocket API for Mozilla's web browser engine, Servo. The project work involved making the Servo's script depend on WebSocket crate.   &lt;br /&gt;
&lt;br /&gt;
==Introduction to Mozilla Servo==&lt;br /&gt;
&lt;br /&gt;
==Project Description==&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95301</id>
		<title>CSC/ECE 517 Spring 2015/oss M1502 GVJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/oss_M1502_GVJ&amp;diff=95301"/>
		<updated>2015-03-22T01:05:07Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: Created page with &amp;quot;Wiki page for websocket&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Wiki page for websocket&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015&amp;diff=95300</id>
		<title>CSC/ECE 517 Spring 2015</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015&amp;diff=95300"/>
		<updated>2015-03-22T01:04:12Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Writing Assignment 1==&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 17 WL]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 5 ZX]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 6 TZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 4 RW]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 7 SA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 9 RA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 14 RI]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 1 DZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 20 HA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 3 RF]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 12 LS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 13 MA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1a 2 WA]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 21 QW]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 23 MS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 10 GL]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 27 VC]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 22 SF]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 15 SH]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/ch1b 18 AS]]&lt;br /&gt;
&lt;br /&gt;
==Writing Assignment 2==&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1502 wwj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1508 MRS]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1504 IMV]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1505 xzl]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1509 lds]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1510 FLP]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1506 SYZ]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss S1504 AAC]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss E1507 DG]]&lt;br /&gt;
*[[CSC/ECE 517 Spring 2015/oss M1502 GVJ]]&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/ch1b_23_MS&amp;diff=94286</id>
		<title>CSC/ECE 517 Spring 2015/ch1b 23 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/ch1b_23_MS&amp;diff=94286"/>
		<updated>2015-02-19T00:41:23Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* [ http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Timeoutable Timeoutable] */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;6&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Devise&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Devise &amp;lt;ref&amp;gt;https://github.com/plataformatec/devise&amp;lt;/ref&amp;gt;''' is a Rails gem used for authenticating and managing users. &lt;br /&gt;
&lt;br /&gt;
The topic write up for this page can be found [https://docs.google.com/a/ncsu.edu/document/d/1Ay5OOUkcLMC-FH61fAm3cNvB3Uyk2hJ09vHnRgqwL-k/edit here].&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
=== Security Background===&lt;br /&gt;
Web applications are relatively easy to attack, as they are simple to understand and manipulate. The Gartner Group estimates that 75% of attacks are at the web application layer, and found out &amp;quot;that out of 300 audited sites, 97% are vulnerable to attack&amp;quot;&amp;lt;ref&amp;gt;http://www.primeon.com/press/article001.php&amp;lt;/ref&amp;gt;.Security depends on the people using the framework, and sometimes on the development method. &lt;br /&gt;
There are several ways to ensure security: Encryption, LDAP, Rails Authentication, Rails Authorization, Rails Captcha, Security Tools and Spam Detection. And devise is for Rails Authentication.&lt;br /&gt;
&lt;br /&gt;
===User Authentication Process ===&lt;br /&gt;
User Authentication is responsible for the following actions:  &lt;br /&gt;
*Signup: create a new user. This user will have to register with a username, password (which will be encrypted in the database), email, and other relevant details. &lt;br /&gt;
*Login: allow a user to sign in with her/his valid username and password. The authentication process happens by matching the username and password in the database, allowing the user access to the protected actions only if the given information matches the recorded values successfully. If not, the user will be redirected to the login page again.&lt;br /&gt;
*Access Restriction: create a session to hold the authenticated user ID after login, so navigation through additional protected actions can be done easily by just checking the userID in the current session.&lt;br /&gt;
*Logout: allow the user to sign out and set the authenticated userID in session file to nil.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Started ==&lt;br /&gt;
===Devise===&lt;br /&gt;
Devise is a flexible authentication solution for Rails helping developers save  time and effort while implementing authentication mechanisms from start. User authentication is a major component of most of the web applications, primarily to determine if the user is in fact, who it is declared to be. Devise is based on Warden&amp;lt;ref&amp;gt;https://github.com/hassox/warden/wiki&amp;lt;/ref&amp;gt;. (Customized [https://github.com/rack/rack Rack] middleware that provides authentication for rack applications). Rack can be considered a middleware between web server such as Mongreal, WEBrick and frameworks such as Rails, Sinatra. &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
To list, Rails can provide the following functionality for a Rails app:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Sign up (create account)&amp;lt;br&amp;gt;&lt;br /&gt;
* Login&amp;lt;br&amp;gt;&lt;br /&gt;
* “Forgot password?” feature&amp;lt;br&amp;gt;&lt;br /&gt;
* “Remember me” (stay logged in) feature&amp;lt;br&amp;gt;&lt;br /&gt;
* Edit account (edit user profile)&amp;lt;br&amp;gt;&lt;br /&gt;
* Validate user details while regestiring&amp;lt;br&amp;gt;&lt;br /&gt;
* Confirm user registration&lt;br /&gt;
&lt;br /&gt;
Current Version: 3.4.1&amp;lt;br&amp;gt;&lt;br /&gt;
First Release: 5 years ago&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Devise===&lt;br /&gt;
Once you have created a Rails app using the &amp;quot;rails new &amp;lt;app name&amp;gt;&amp;quot; command we first need to add a line to the &amp;quot;Gemfile&amp;quot; using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;gem 'devise'&amp;quot; &amp;gt;&amp;gt; Gemfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then install the gem using:&lt;br /&gt;
&amp;lt;pre&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
The Gem will be installed for your rails application. Then run the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:install          &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create config files.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise user              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To create model(User) class and routes and to also associate the 'User' model with 'Devise'.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:migrate                        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To run the migration and create the table with certain fields appropriate for user authentication. The result should be something like: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrating ================================&lt;br /&gt;
-- create_table(:users)&lt;br /&gt;
   -&amp;gt; 0.0178s&lt;br /&gt;
-- add_index(:users, :email, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0010s&lt;br /&gt;
-- add_index(:users, :reset_password_token, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0055s&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrated (0.0255s) =======================&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:views users      &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create the directory /app/views/users with all the devise views, such as login form, registration form .&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Methods==&lt;br /&gt;
Devise provides classes, models, views, controllers, views, helpers, routes. However, these functionality are exposed in only a small number of helper methods,   not all of these components would be required to know. Some of the important Devise helper methods provided are:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Method: authenticate_user!====&lt;br /&gt;
The &amp;lt;i&amp;gt;authenticate_user!&amp;lt;/i&amp;gt; method is a class method that can be called from a controller only. The method determines if the user has access to all or a specific set of controller actions. This method is invoked via a &amp;lt;i&amp;gt;before_filter&amp;lt;/i&amp;gt;, for example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The above statements requires the user to be logged in before they can access the controller actions. To make exceptions for accessing any actions without authentications we can update the above statement as:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before_action :authenticate_user!, except: [:show]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above example, user authentication would be required to call any actions in the controller except the &amp;lt;i&amp;gt;show&amp;lt;/i&amp;gt; action. &lt;br /&gt;
So if the &amp;lt;i&amp;gt;root&amp;lt;/i&amp;gt; in the &amp;lt;code&amp;gt;config/routes.rb&amp;lt;/code&amp;gt; field is set to obtain any view belonging to the UsersController in this case, the Sign in page will be loaded before any of the actions can be accessed. &amp;lt;br&amp;gt; Once the user is authenticate, the required action is obtained.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: current_user====&lt;br /&gt;
The &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method is used to return the model class to whom the signed in user belongs. The method returns nil if a user has not yet signed in. &lt;br /&gt;
The &amp;lt;authenticate_user!&amp;gt; will make sure that the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method would never return &amp;lt;i&amp;gt;nil&amp;lt;/i&amp;gt;. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_signed_in?====&lt;br /&gt;
Checks if the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method returns a non nil value. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: sign_in(@user) and sign_out(@user)====&lt;br /&gt;
The sign_in(@user) and the sign_out(@user) are useful to login or logout a newly created user.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_session====&lt;br /&gt;
This method returns metadata regarding the logged in user.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Modules==&lt;br /&gt;
Devise is composed of 10 modules that help Devise in providing user management functionality:&lt;br /&gt;
===[http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/DatabaseAuthenticatable Database Authenticatable]===&lt;br /&gt;
Ensures that the user has entered the correct password and also to encrypt and stores the password in the database when the user registers for the first time. The authentication can be done both through POST requests or HTTP Basic Authentication.&amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).valid_password?('password123')         # returns true/false &amp;lt;/pre&amp;gt;&lt;br /&gt;
===[http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Omniauthable Omniauthable]===&lt;br /&gt;
Adds OmniAuth (https://github.com/intridea/omniauth) support.&amp;lt;br&amp;gt;&lt;br /&gt;
===[http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Confirmable Confirmable]===&lt;br /&gt;
Sends confirmation emails to Users following successful registration. This is to prevent bot registrations. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).confirm!      # returns true unless it's already confirmed&lt;br /&gt;
User.find(1).confirmed?    # true/false&lt;br /&gt;
User.find(1).send_confirmation_instructions # manually send instructions&amp;lt;/pre&amp;gt;&lt;br /&gt;
===[http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Recoverable Recoverable]===&lt;br /&gt;
Resets the user password and sends reset instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;# resets the user password and save the record, true if valid passwords are given, otherwise false&lt;br /&gt;
User.find(1).reset_password!('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# only resets the user password, without saving the record&lt;br /&gt;
user = User.find(1)&lt;br /&gt;
user.reset_password('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# creates a new token and send it with instructions about how to reset the password&lt;br /&gt;
User.find(1).send_reset_password_instructions &amp;lt;/pre&amp;gt;&lt;br /&gt;
===[http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Registerable Registerable]===&lt;br /&gt;
Handles signing up users through a registration process, also allowing them to edit and destroy their account.&amp;lt;br&amp;gt;&lt;br /&gt;
Helps user to register themselves and also to make changes to their login credentials including deleting their account. &lt;br /&gt;
===[http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Rememberable Rememberable]=== &lt;br /&gt;
Cookie handling module to manage generating and clearing of tokens for remembering the user.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;User.find(1).remember_me!  # regenerating the token&lt;br /&gt;
User.find(1).forget_me!    # clearing the token&lt;br /&gt;
&lt;br /&gt;
# generating info to put into cookies&lt;br /&gt;
User.serialize_into_cookie(user)&lt;br /&gt;
&lt;br /&gt;
# lookup the user based on the incoming cookie information&lt;br /&gt;
User.serialize_from_cookie(cookie_string)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===[http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Trackable Trackable]=== &lt;br /&gt;
Tracks login details for a specific user using log in count, last log in, IP address. These details help Site admin to investigate any unusual activity.&amp;lt;br&amp;gt; &lt;br /&gt;
===[http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Timeoutable Timeoutable]===&lt;br /&gt;
Expires sessions that have not been active in a specified period of time.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===[http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Validatable Validatable]===&lt;br /&gt;
Provides validations of email and password to make sure that the log in details follow a given format. These can be modified to have customized validations.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;#email_required? ⇒ Boolean protected&lt;br /&gt;
#password_required? ⇒ Boolean protected&amp;lt;/pre&amp;gt;&lt;br /&gt;
===[http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Lockable Lockable]===&lt;br /&gt;
Locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example application &amp;lt;ref&amp;gt;http://www.gotealeaf.com/blog/how-to-use-devise-in-rails-for-authentication&amp;lt;/ref&amp;gt;==&lt;br /&gt;
Consider an application that can be accessed by an end user and a site admin. Since the admin would have extra priviledges, partitioned access would be required. This can be implemented by representing both types of users as seperate models and having their respective controller with appropiate actions.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# All administrator controllers should inherit from this controller&lt;br /&gt;
class AdminController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :authenticate_admin!&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# All end-user controllers should inherit from this controller&lt;br /&gt;
class EndUserController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
An alternate implementaton method would be to have just one user(model) but with an &amp;lt;code&amp;gt;admin&amp;lt;/code&amp;gt; flag set to true for the admin in the model record. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationController &amp;lt; ActionController::Base&lt;br /&gt;
  before_filer :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# All administrative controllers should inherit from this controller&lt;br /&gt;
class AdminController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :ensure_admin!&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def ensure_admin!&lt;br /&gt;
    unless current_user.admin?&lt;br /&gt;
      sign_out current_user&lt;br /&gt;
&lt;br /&gt;
      redirect_to root_path&lt;br /&gt;
&lt;br /&gt;
      return false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
With this way specific controllers can have private methods. In this case, the private method checks if the user is an admin or not. Only if the user is an admin, can they access &amp;lt;i&amp;gt;AdminController&amp;lt;/i&amp;gt; actions&lt;br /&gt;
&lt;br /&gt;
==Rails-Devise-Pundit&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise-pundit&amp;lt;/ref&amp;gt;==&lt;br /&gt;
Pundit extends the Devise funtionailty by providing authorization services in addition to the authentication funtionality provided by Devise.  Pundit can be used to implement user roles, and limit access to pages based on user role. &lt;br /&gt;
To exemplify, Pundit can provide following features:&amp;lt;br&amp;gt;&lt;br /&gt;
* An admin can see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
* An admin can change a user’s role&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t change their role&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t see (or edit) another user’s profile&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can see (and edit) their own user profile&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Other Rails Authentication==&lt;br /&gt;
OmniAuth&amp;lt;ref&amp;gt;&amp;quot;https://github.com/intridea/omniauth&amp;quot;&amp;lt;/ref&amp;gt;: A generalized Rack framework for multiple-provider authentication.&amp;lt;br&amp;gt;&lt;br /&gt;
Authlogic&amp;lt;ref&amp;gt;https://github.com/binarylogic/authlogic&amp;lt;/ref&amp;gt;: A clean, simple, and unobtrusive ruby authentication solution.&amp;lt;br&amp;gt;&lt;br /&gt;
Restful-authentication&amp;lt;ref&amp;gt;https://github.com/technoweenie/restful-authentication&amp;lt;/ref&amp;gt;: Generates common user authentication code for Rails/Merb, with a full test/unit and rspec suite and optional Acts as State Machine support built-in.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Devise is the most popular Rails Authentication tools. It provides a full gamut of features, and can be configured to meet most requirements. Devise often interacts with Warden which does not provide helper methods, controller classes, views, configuration options and log in failure handling. All of these things are what Devise supplies. So if you need to extend or augment Devise, you may need to implement a customized Strategy class for your own.&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/ch1b_23_MS&amp;diff=94285</id>
		<title>CSC/ECE 517 Spring 2015/ch1b 23 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/ch1b_23_MS&amp;diff=94285"/>
		<updated>2015-02-19T00:41:01Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Devise Modules */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;6&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Devise&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Devise &amp;lt;ref&amp;gt;https://github.com/plataformatec/devise&amp;lt;/ref&amp;gt;''' is a Rails gem used for authenticating and managing users. &lt;br /&gt;
&lt;br /&gt;
The topic write up for this page can be found [https://docs.google.com/a/ncsu.edu/document/d/1Ay5OOUkcLMC-FH61fAm3cNvB3Uyk2hJ09vHnRgqwL-k/edit here].&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
=== Security Background===&lt;br /&gt;
Web applications are relatively easy to attack, as they are simple to understand and manipulate. The Gartner Group estimates that 75% of attacks are at the web application layer, and found out &amp;quot;that out of 300 audited sites, 97% are vulnerable to attack&amp;quot;&amp;lt;ref&amp;gt;http://www.primeon.com/press/article001.php&amp;lt;/ref&amp;gt;.Security depends on the people using the framework, and sometimes on the development method. &lt;br /&gt;
There are several ways to ensure security: Encryption, LDAP, Rails Authentication, Rails Authorization, Rails Captcha, Security Tools and Spam Detection. And devise is for Rails Authentication.&lt;br /&gt;
&lt;br /&gt;
===User Authentication Process ===&lt;br /&gt;
User Authentication is responsible for the following actions:  &lt;br /&gt;
*Signup: create a new user. This user will have to register with a username, password (which will be encrypted in the database), email, and other relevant details. &lt;br /&gt;
*Login: allow a user to sign in with her/his valid username and password. The authentication process happens by matching the username and password in the database, allowing the user access to the protected actions only if the given information matches the recorded values successfully. If not, the user will be redirected to the login page again.&lt;br /&gt;
*Access Restriction: create a session to hold the authenticated user ID after login, so navigation through additional protected actions can be done easily by just checking the userID in the current session.&lt;br /&gt;
*Logout: allow the user to sign out and set the authenticated userID in session file to nil.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Started ==&lt;br /&gt;
===Devise===&lt;br /&gt;
Devise is a flexible authentication solution for Rails helping developers save  time and effort while implementing authentication mechanisms from start. User authentication is a major component of most of the web applications, primarily to determine if the user is in fact, who it is declared to be. Devise is based on Warden&amp;lt;ref&amp;gt;https://github.com/hassox/warden/wiki&amp;lt;/ref&amp;gt;. (Customized [https://github.com/rack/rack Rack] middleware that provides authentication for rack applications). Rack can be considered a middleware between web server such as Mongreal, WEBrick and frameworks such as Rails, Sinatra. &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
To list, Rails can provide the following functionality for a Rails app:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Sign up (create account)&amp;lt;br&amp;gt;&lt;br /&gt;
* Login&amp;lt;br&amp;gt;&lt;br /&gt;
* “Forgot password?” feature&amp;lt;br&amp;gt;&lt;br /&gt;
* “Remember me” (stay logged in) feature&amp;lt;br&amp;gt;&lt;br /&gt;
* Edit account (edit user profile)&amp;lt;br&amp;gt;&lt;br /&gt;
* Validate user details while regestiring&amp;lt;br&amp;gt;&lt;br /&gt;
* Confirm user registration&lt;br /&gt;
&lt;br /&gt;
Current Version: 3.4.1&amp;lt;br&amp;gt;&lt;br /&gt;
First Release: 5 years ago&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Devise===&lt;br /&gt;
Once you have created a Rails app using the &amp;quot;rails new &amp;lt;app name&amp;gt;&amp;quot; command we first need to add a line to the &amp;quot;Gemfile&amp;quot; using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;gem 'devise'&amp;quot; &amp;gt;&amp;gt; Gemfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then install the gem using:&lt;br /&gt;
&amp;lt;pre&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
The Gem will be installed for your rails application. Then run the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:install          &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create config files.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise user              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To create model(User) class and routes and to also associate the 'User' model with 'Devise'.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:migrate                        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To run the migration and create the table with certain fields appropriate for user authentication. The result should be something like: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrating ================================&lt;br /&gt;
-- create_table(:users)&lt;br /&gt;
   -&amp;gt; 0.0178s&lt;br /&gt;
-- add_index(:users, :email, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0010s&lt;br /&gt;
-- add_index(:users, :reset_password_token, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0055s&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrated (0.0255s) =======================&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:views users      &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create the directory /app/views/users with all the devise views, such as login form, registration form .&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Methods==&lt;br /&gt;
Devise provides classes, models, views, controllers, views, helpers, routes. However, these functionality are exposed in only a small number of helper methods,   not all of these components would be required to know. Some of the important Devise helper methods provided are:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Method: authenticate_user!====&lt;br /&gt;
The &amp;lt;i&amp;gt;authenticate_user!&amp;lt;/i&amp;gt; method is a class method that can be called from a controller only. The method determines if the user has access to all or a specific set of controller actions. This method is invoked via a &amp;lt;i&amp;gt;before_filter&amp;lt;/i&amp;gt;, for example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The above statements requires the user to be logged in before they can access the controller actions. To make exceptions for accessing any actions without authentications we can update the above statement as:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before_action :authenticate_user!, except: [:show]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above example, user authentication would be required to call any actions in the controller except the &amp;lt;i&amp;gt;show&amp;lt;/i&amp;gt; action. &lt;br /&gt;
So if the &amp;lt;i&amp;gt;root&amp;lt;/i&amp;gt; in the &amp;lt;code&amp;gt;config/routes.rb&amp;lt;/code&amp;gt; field is set to obtain any view belonging to the UsersController in this case, the Sign in page will be loaded before any of the actions can be accessed. &amp;lt;br&amp;gt; Once the user is authenticate, the required action is obtained.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: current_user====&lt;br /&gt;
The &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method is used to return the model class to whom the signed in user belongs. The method returns nil if a user has not yet signed in. &lt;br /&gt;
The &amp;lt;authenticate_user!&amp;gt; will make sure that the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method would never return &amp;lt;i&amp;gt;nil&amp;lt;/i&amp;gt;. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_signed_in?====&lt;br /&gt;
Checks if the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method returns a non nil value. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: sign_in(@user) and sign_out(@user)====&lt;br /&gt;
The sign_in(@user) and the sign_out(@user) are useful to login or logout a newly created user.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_session====&lt;br /&gt;
This method returns metadata regarding the logged in user.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Modules==&lt;br /&gt;
Devise is composed of 10 modules that help Devise in providing user management functionality:&lt;br /&gt;
===[http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/DatabaseAuthenticatable Database Authenticatable]===&lt;br /&gt;
Ensures that the user has entered the correct password and also to encrypt and stores the password in the database when the user registers for the first time. The authentication can be done both through POST requests or HTTP Basic Authentication.&amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).valid_password?('password123')         # returns true/false &amp;lt;/pre&amp;gt;&lt;br /&gt;
===[http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Omniauthable Omniauthable]===&lt;br /&gt;
Adds OmniAuth (https://github.com/intridea/omniauth) support.&amp;lt;br&amp;gt;&lt;br /&gt;
===[http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Confirmable Confirmable]===&lt;br /&gt;
Sends confirmation emails to Users following successful registration. This is to prevent bot registrations. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).confirm!      # returns true unless it's already confirmed&lt;br /&gt;
User.find(1).confirmed?    # true/false&lt;br /&gt;
User.find(1).send_confirmation_instructions # manually send instructions&amp;lt;/pre&amp;gt;&lt;br /&gt;
===[http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Recoverable Recoverable]===&lt;br /&gt;
Resets the user password and sends reset instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;# resets the user password and save the record, true if valid passwords are given, otherwise false&lt;br /&gt;
User.find(1).reset_password!('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# only resets the user password, without saving the record&lt;br /&gt;
user = User.find(1)&lt;br /&gt;
user.reset_password('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# creates a new token and send it with instructions about how to reset the password&lt;br /&gt;
User.find(1).send_reset_password_instructions &amp;lt;/pre&amp;gt;&lt;br /&gt;
===[http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Registerable Registerable]===&lt;br /&gt;
Handles signing up users through a registration process, also allowing them to edit and destroy their account.&amp;lt;br&amp;gt;&lt;br /&gt;
Helps user to register themselves and also to make changes to their login credentials including deleting their account. &lt;br /&gt;
===[http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Rememberable Rememberable]=== &lt;br /&gt;
Cookie handling module to manage generating and clearing of tokens for remembering the user.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;User.find(1).remember_me!  # regenerating the token&lt;br /&gt;
User.find(1).forget_me!    # clearing the token&lt;br /&gt;
&lt;br /&gt;
# generating info to put into cookies&lt;br /&gt;
User.serialize_into_cookie(user)&lt;br /&gt;
&lt;br /&gt;
# lookup the user based on the incoming cookie information&lt;br /&gt;
User.serialize_from_cookie(cookie_string)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===[http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Trackable Trackable]=== &lt;br /&gt;
Tracks login details for a specific user using log in count, last log in, IP address. These details help Site admin to investigate any unusual activity.&amp;lt;br&amp;gt; &lt;br /&gt;
===[ http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Timeoutable Timeoutable]===&lt;br /&gt;
Expires sessions that have not been active in a specified period of time.&amp;lt;br&amp;gt;&lt;br /&gt;
===[http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Validatable Validatable]===&lt;br /&gt;
Provides validations of email and password to make sure that the log in details follow a given format. These can be modified to have customized validations.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;#email_required? ⇒ Boolean protected&lt;br /&gt;
#password_required? ⇒ Boolean protected&amp;lt;/pre&amp;gt;&lt;br /&gt;
===[http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Lockable Lockable]===&lt;br /&gt;
Locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example application &amp;lt;ref&amp;gt;http://www.gotealeaf.com/blog/how-to-use-devise-in-rails-for-authentication&amp;lt;/ref&amp;gt;==&lt;br /&gt;
Consider an application that can be accessed by an end user and a site admin. Since the admin would have extra priviledges, partitioned access would be required. This can be implemented by representing both types of users as seperate models and having their respective controller with appropiate actions.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# All administrator controllers should inherit from this controller&lt;br /&gt;
class AdminController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :authenticate_admin!&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# All end-user controllers should inherit from this controller&lt;br /&gt;
class EndUserController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
An alternate implementaton method would be to have just one user(model) but with an &amp;lt;code&amp;gt;admin&amp;lt;/code&amp;gt; flag set to true for the admin in the model record. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationController &amp;lt; ActionController::Base&lt;br /&gt;
  before_filer :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# All administrative controllers should inherit from this controller&lt;br /&gt;
class AdminController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :ensure_admin!&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def ensure_admin!&lt;br /&gt;
    unless current_user.admin?&lt;br /&gt;
      sign_out current_user&lt;br /&gt;
&lt;br /&gt;
      redirect_to root_path&lt;br /&gt;
&lt;br /&gt;
      return false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
With this way specific controllers can have private methods. In this case, the private method checks if the user is an admin or not. Only if the user is an admin, can they access &amp;lt;i&amp;gt;AdminController&amp;lt;/i&amp;gt; actions&lt;br /&gt;
&lt;br /&gt;
==Rails-Devise-Pundit&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise-pundit&amp;lt;/ref&amp;gt;==&lt;br /&gt;
Pundit extends the Devise funtionailty by providing authorization services in addition to the authentication funtionality provided by Devise.  Pundit can be used to implement user roles, and limit access to pages based on user role. &lt;br /&gt;
To exemplify, Pundit can provide following features:&amp;lt;br&amp;gt;&lt;br /&gt;
* An admin can see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
* An admin can change a user’s role&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t change their role&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t see (or edit) another user’s profile&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can see (and edit) their own user profile&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Other Rails Authentication==&lt;br /&gt;
OmniAuth&amp;lt;ref&amp;gt;&amp;quot;https://github.com/intridea/omniauth&amp;quot;&amp;lt;/ref&amp;gt;: A generalized Rack framework for multiple-provider authentication.&amp;lt;br&amp;gt;&lt;br /&gt;
Authlogic&amp;lt;ref&amp;gt;https://github.com/binarylogic/authlogic&amp;lt;/ref&amp;gt;: A clean, simple, and unobtrusive ruby authentication solution.&amp;lt;br&amp;gt;&lt;br /&gt;
Restful-authentication&amp;lt;ref&amp;gt;https://github.com/technoweenie/restful-authentication&amp;lt;/ref&amp;gt;: Generates common user authentication code for Rails/Merb, with a full test/unit and rspec suite and optional Acts as State Machine support built-in.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Devise is the most popular Rails Authentication tools. It provides a full gamut of features, and can be configured to meet most requirements. Devise often interacts with Warden which does not provide helper methods, controller classes, views, configuration options and log in failure handling. All of these things are what Devise supplies. So if you need to extend or augment Devise, you may need to implement a customized Strategy class for your own.&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/ch1b_23_MS&amp;diff=94284</id>
		<title>CSC/ECE 517 Spring 2015/ch1b 23 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/ch1b_23_MS&amp;diff=94284"/>
		<updated>2015-02-19T00:29:11Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Example application */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;6&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Devise&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Devise &amp;lt;ref&amp;gt;https://github.com/plataformatec/devise&amp;lt;/ref&amp;gt;''' is a Rails gem used for authenticating and managing users. &lt;br /&gt;
&lt;br /&gt;
The topic write up for this page can be found [https://docs.google.com/a/ncsu.edu/document/d/1Ay5OOUkcLMC-FH61fAm3cNvB3Uyk2hJ09vHnRgqwL-k/edit here].&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
=== Security Background===&lt;br /&gt;
Web applications are relatively easy to attack, as they are simple to understand and manipulate. The Gartner Group estimates that 75% of attacks are at the web application layer, and found out &amp;quot;that out of 300 audited sites, 97% are vulnerable to attack&amp;quot;&amp;lt;ref&amp;gt;http://www.primeon.com/press/article001.php&amp;lt;/ref&amp;gt;.Security depends on the people using the framework, and sometimes on the development method. &lt;br /&gt;
There are several ways to ensure security: Encryption, LDAP, Rails Authentication, Rails Authorization, Rails Captcha, Security Tools and Spam Detection. And devise is for Rails Authentication.&lt;br /&gt;
&lt;br /&gt;
===User Authentication Process ===&lt;br /&gt;
User Authentication is responsible for the following actions:  &lt;br /&gt;
*Signup: create a new user. This user will have to register with a username, password (which will be encrypted in the database), email, and other relevant details. &lt;br /&gt;
*Login: allow a user to sign in with her/his valid username and password. The authentication process happens by matching the username and password in the database, allowing the user access to the protected actions only if the given information matches the recorded values successfully. If not, the user will be redirected to the login page again.&lt;br /&gt;
*Access Restriction: create a session to hold the authenticated user ID after login, so navigation through additional protected actions can be done easily by just checking the userID in the current session.&lt;br /&gt;
*Logout: allow the user to sign out and set the authenticated userID in session file to nil.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Started ==&lt;br /&gt;
===Devise===&lt;br /&gt;
Devise is a flexible authentication solution for Rails helping developers save  time and effort while implementing authentication mechanisms from start. User authentication is a major component of most of the web applications, primarily to determine if the user is in fact, who it is declared to be. Devise is based on Warden&amp;lt;ref&amp;gt;https://github.com/hassox/warden/wiki&amp;lt;/ref&amp;gt;. (Customized [https://github.com/rack/rack Rack] middleware that provides authentication for rack applications). Rack can be considered a middleware between web server such as Mongreal, WEBrick and frameworks such as Rails, Sinatra. &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
To list, Rails can provide the following functionality for a Rails app:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Sign up (create account)&amp;lt;br&amp;gt;&lt;br /&gt;
* Login&amp;lt;br&amp;gt;&lt;br /&gt;
* “Forgot password?” feature&amp;lt;br&amp;gt;&lt;br /&gt;
* “Remember me” (stay logged in) feature&amp;lt;br&amp;gt;&lt;br /&gt;
* Edit account (edit user profile)&amp;lt;br&amp;gt;&lt;br /&gt;
* Validate user details while regestiring&amp;lt;br&amp;gt;&lt;br /&gt;
* Confirm user registration&lt;br /&gt;
&lt;br /&gt;
Current Version: 3.4.1&amp;lt;br&amp;gt;&lt;br /&gt;
First Release: 5 years ago&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Devise===&lt;br /&gt;
Once you have created a Rails app using the &amp;quot;rails new &amp;lt;app name&amp;gt;&amp;quot; command we first need to add a line to the &amp;quot;Gemfile&amp;quot; using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;gem 'devise'&amp;quot; &amp;gt;&amp;gt; Gemfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then install the gem using:&lt;br /&gt;
&amp;lt;pre&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
The Gem will be installed for your rails application. Then run the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:install          &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create config files.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise user              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To create model(User) class and routes and to also associate the 'User' model with 'Devise'.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:migrate                        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To run the migration and create the table with certain fields appropriate for user authentication. The result should be something like: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrating ================================&lt;br /&gt;
-- create_table(:users)&lt;br /&gt;
   -&amp;gt; 0.0178s&lt;br /&gt;
-- add_index(:users, :email, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0010s&lt;br /&gt;
-- add_index(:users, :reset_password_token, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0055s&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrated (0.0255s) =======================&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:views users      &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create the directory /app/views/users with all the devise views, such as login form, registration form .&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Methods==&lt;br /&gt;
Devise provides classes, models, views, controllers, views, helpers, routes. However, these functionality are exposed in only a small number of helper methods,   not all of these components would be required to know. Some of the important Devise helper methods provided are:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Method: authenticate_user!====&lt;br /&gt;
The &amp;lt;i&amp;gt;authenticate_user!&amp;lt;/i&amp;gt; method is a class method that can be called from a controller only. The method determines if the user has access to all or a specific set of controller actions. This method is invoked via a &amp;lt;i&amp;gt;before_filter&amp;lt;/i&amp;gt;, for example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The above statements requires the user to be logged in before they can access the controller actions. To make exceptions for accessing any actions without authentications we can update the above statement as:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before_action :authenticate_user!, except: [:show]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above example, user authentication would be required to call any actions in the controller except the &amp;lt;i&amp;gt;show&amp;lt;/i&amp;gt; action. &lt;br /&gt;
So if the &amp;lt;i&amp;gt;root&amp;lt;/i&amp;gt; in the &amp;lt;code&amp;gt;config/routes.rb&amp;lt;/code&amp;gt; field is set to obtain any view belonging to the UsersController in this case, the Sign in page will be loaded before any of the actions can be accessed. &amp;lt;br&amp;gt; Once the user is authenticate, the required action is obtained.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: current_user====&lt;br /&gt;
The &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method is used to return the model class to whom the signed in user belongs. The method returns nil if a user has not yet signed in. &lt;br /&gt;
The &amp;lt;authenticate_user!&amp;gt; will make sure that the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method would never return &amp;lt;i&amp;gt;nil&amp;lt;/i&amp;gt;. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_signed_in?====&lt;br /&gt;
Checks if the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method returns a non nil value. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: sign_in(@user) and sign_out(@user)====&lt;br /&gt;
The sign_in(@user) and the sign_out(@user) are useful to login or logout a newly created user.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_session====&lt;br /&gt;
This method returns metadata regarding the logged in user.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Modules==&lt;br /&gt;
===Database Authenticatable===&lt;br /&gt;
Ensures that the user has entered the correct password and also to encrypt and stores the password in the database when the user registers for the first time. The authentication can be done both through POST requests or HTTP Basic Authentication.&amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).valid_password?('password123')         # returns true/false &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Omniauthable===&lt;br /&gt;
Adds OmniAuth (https://github.com/intridea/omniauth) support.&amp;lt;br&amp;gt;&lt;br /&gt;
===Confirmable===&lt;br /&gt;
Sends confirmation emails to Users following successful registration. This is to prevent bot registrations. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).confirm!      # returns true unless it's already confirmed&lt;br /&gt;
User.find(1).confirmed?    # true/false&lt;br /&gt;
User.find(1).send_confirmation_instructions # manually send instructions&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Recoverable===&lt;br /&gt;
Resets the user password and sends reset instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;# resets the user password and save the record, true if valid passwords are given, otherwise false&lt;br /&gt;
User.find(1).reset_password!('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# only resets the user password, without saving the record&lt;br /&gt;
user = User.find(1)&lt;br /&gt;
user.reset_password('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# creates a new token and send it with instructions about how to reset the password&lt;br /&gt;
User.find(1).send_reset_password_instructions &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Registerable===&lt;br /&gt;
Handles signing up users through a registration process, also allowing them to edit and destroy their account.&amp;lt;br&amp;gt;&lt;br /&gt;
Helps user to register themselves and also to make changes to their login credentials including deleting their account. &lt;br /&gt;
===Rememberable=== &lt;br /&gt;
Cookie handling module to manage generating and clearing of tokens for remembering the user.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;User.find(1).remember_me!  # regenerating the token&lt;br /&gt;
User.find(1).forget_me!    # clearing the token&lt;br /&gt;
&lt;br /&gt;
# generating info to put into cookies&lt;br /&gt;
User.serialize_into_cookie(user)&lt;br /&gt;
&lt;br /&gt;
# lookup the user based on the incoming cookie information&lt;br /&gt;
User.serialize_from_cookie(cookie_string)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trackable=== &lt;br /&gt;
Tracks login details for a specific user using log in count, last log in, IP address. These details help Site admin to investigate any unusual activity.&amp;lt;br&amp;gt; &lt;br /&gt;
===Timeoutable===&lt;br /&gt;
Expires sessions that have not been active in a specified period of time.&amp;lt;br&amp;gt;&lt;br /&gt;
===Validatable===&lt;br /&gt;
Provides validations of email and password to make sure that the log in details follow a given format. These can be modified to have customized validations.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;#email_required? ⇒ Boolean protected&lt;br /&gt;
#password_required? ⇒ Boolean protected&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Lockable===&lt;br /&gt;
Locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example application &amp;lt;ref&amp;gt;http://www.gotealeaf.com/blog/how-to-use-devise-in-rails-for-authentication&amp;lt;/ref&amp;gt;==&lt;br /&gt;
Consider an application that can be accessed by an end user and a site admin. Since the admin would have extra priviledges, partitioned access would be required. This can be implemented by representing both types of users as seperate models and having their respective controller with appropiate actions.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# All administrator controllers should inherit from this controller&lt;br /&gt;
class AdminController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :authenticate_admin!&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# All end-user controllers should inherit from this controller&lt;br /&gt;
class EndUserController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
An alternate implementaton method would be to have just one user(model) but with an &amp;lt;code&amp;gt;admin&amp;lt;/code&amp;gt; flag set to true for the admin in the model record. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationController &amp;lt; ActionController::Base&lt;br /&gt;
  before_filer :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# All administrative controllers should inherit from this controller&lt;br /&gt;
class AdminController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :ensure_admin!&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def ensure_admin!&lt;br /&gt;
    unless current_user.admin?&lt;br /&gt;
      sign_out current_user&lt;br /&gt;
&lt;br /&gt;
      redirect_to root_path&lt;br /&gt;
&lt;br /&gt;
      return false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
With this way specific controllers can have private methods. In this case, the private method checks if the user is an admin or not. Only if the user is an admin, can they access &amp;lt;i&amp;gt;AdminController&amp;lt;/i&amp;gt; actions&lt;br /&gt;
&lt;br /&gt;
==Rails-Devise-Pundit&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise-pundit&amp;lt;/ref&amp;gt;==&lt;br /&gt;
Pundit extends the Devise funtionailty by providing authorization services in addition to the authentication funtionality provided by Devise.  Pundit can be used to implement user roles, and limit access to pages based on user role. &lt;br /&gt;
To exemplify, Pundit can provide following features:&amp;lt;br&amp;gt;&lt;br /&gt;
* An admin can see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
* An admin can change a user’s role&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t change their role&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t see (or edit) another user’s profile&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can see (and edit) their own user profile&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Other Rails Authentication==&lt;br /&gt;
OmniAuth&amp;lt;ref&amp;gt;&amp;quot;https://github.com/intridea/omniauth&amp;quot;&amp;lt;/ref&amp;gt;: A generalized Rack framework for multiple-provider authentication.&amp;lt;br&amp;gt;&lt;br /&gt;
Authlogic&amp;lt;ref&amp;gt;https://github.com/binarylogic/authlogic&amp;lt;/ref&amp;gt;: A clean, simple, and unobtrusive ruby authentication solution.&amp;lt;br&amp;gt;&lt;br /&gt;
Restful-authentication&amp;lt;ref&amp;gt;https://github.com/technoweenie/restful-authentication&amp;lt;/ref&amp;gt;: Generates common user authentication code for Rails/Merb, with a full test/unit and rspec suite and optional Acts as State Machine support built-in.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Devise is the most popular Rails Authentication tools. It provides a full gamut of features, and can be configured to meet most requirements. Devise often interacts with Warden which does not provide helper methods, controller classes, views, configuration options and log in failure handling. All of these things are what Devise supplies. So if you need to extend or augment Devise, you may need to implement a customized Strategy class for your own.&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/ch1b_23_MS&amp;diff=94272</id>
		<title>CSC/ECE 517 Spring 2015/ch1b 23 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/ch1b_23_MS&amp;diff=94272"/>
		<updated>2015-02-18T22:53:48Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;6&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Devise&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Devise &amp;lt;ref&amp;gt;https://github.com/plataformatec/devise&amp;lt;/ref&amp;gt;''' is a Rails gem used for authenticating and managing users. &lt;br /&gt;
&lt;br /&gt;
The topic write up for this page can be found [https://docs.google.com/a/ncsu.edu/document/d/1Ay5OOUkcLMC-FH61fAm3cNvB3Uyk2hJ09vHnRgqwL-k/edit here].&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
=== Security Background===&lt;br /&gt;
Web applications are relatively easy to attack, as they are simple to understand and manipulate. The Gartner Group estimates that 75% of attacks are at the web application layer, and found out &amp;quot;that out of 300 audited sites, 97% are vulnerable to attack&amp;quot;&amp;lt;ref&amp;gt;http://www.primeon.com/press/article001.php&amp;lt;/ref&amp;gt;.Security depends on the people using the framework, and sometimes on the development method. &lt;br /&gt;
There are several ways to ensure security: Encryption, LDAP, Rails Authentication, Rails Authorization, Rails Captcha, Security Tools and Spam Detection. And devise is for Rails Authentication.&lt;br /&gt;
&lt;br /&gt;
===User Authentication Process ===&lt;br /&gt;
User Authentication is responsible for the following actions:  &lt;br /&gt;
*Signup: create a new user. This user will have to register with a username, password (which will be encrypted in the database), email, and other relevant details. &lt;br /&gt;
*Login: allow a user to sign in with her/his valid username and password. The authentication process happens by matching the username and password in the database, allowing the user access to the protected actions only if the given information matches the recorded values successfully. If not, the user will be redirected to the login page again.&lt;br /&gt;
*Access Restriction: create a session to hold the authenticated user ID after login, so navigation through additional protected actions can be done easily by just checking the userID in the current session.&lt;br /&gt;
*Logout: allow the user to sign out and set the authenticated userID in session file to nil.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Started ==&lt;br /&gt;
===Devise===&lt;br /&gt;
Devise is a flexible authentication solution for Rails helping developers save  time and effort while implementing authentication mechanisms from start. User authentication is a major component of most of the web applications, primarily to determine if the user is in fact, who it is declared to be. Devise is based on Warden&amp;lt;ref&amp;gt;https://github.com/hassox/warden/wiki&amp;lt;/ref&amp;gt;. (Customized [https://github.com/rack/rack Rack] middleware that provides authentication for rack applications). Rack can be considered a middleware between web server such as Mongreal, WEBrick and frameworks such as Rails, Sinatra. &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
To list, Rails can provide the following functionality for a Rails app:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Sign up (create account)&amp;lt;br&amp;gt;&lt;br /&gt;
* Login&amp;lt;br&amp;gt;&lt;br /&gt;
* “Forgot password?” feature&amp;lt;br&amp;gt;&lt;br /&gt;
* “Remember me” (stay logged in) feature&amp;lt;br&amp;gt;&lt;br /&gt;
* Edit account (edit user profile)&amp;lt;br&amp;gt;&lt;br /&gt;
* Validate user details while regestiring&amp;lt;br&amp;gt;&lt;br /&gt;
* Confirm user registration&lt;br /&gt;
&lt;br /&gt;
Current Version: 3.4.1&amp;lt;br&amp;gt;&lt;br /&gt;
First Release: 5 years ago&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Devise===&lt;br /&gt;
Once you have created a Rails app using the &amp;quot;rails new &amp;lt;app name&amp;gt;&amp;quot; command we first need to add a line to the &amp;quot;Gemfile&amp;quot; using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;gem 'devise'&amp;quot; &amp;gt;&amp;gt; Gemfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then install the gem using:&lt;br /&gt;
&amp;lt;pre&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
The Gem will be installed for your rails application. Then run the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:install          &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create config files.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise user              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To create model(User) class and routes and to also associate the 'User' model with 'Devise'.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:migrate                        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To run the migration and create the table with certain fields appropriate for user authentication. The result should be something like: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrating ================================&lt;br /&gt;
-- create_table(:users)&lt;br /&gt;
   -&amp;gt; 0.0178s&lt;br /&gt;
-- add_index(:users, :email, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0010s&lt;br /&gt;
-- add_index(:users, :reset_password_token, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0055s&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrated (0.0255s) =======================&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:views users      &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create the directory /app/views/users with all the devise views, such as login form, registration form .&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Methods==&lt;br /&gt;
Devise provides classes, models, views, controllers, views, helpers, routes. However, these functionality are exposed in only a small number of helper methods,   not all of these components would be required to know. Some of the important Devise helper methods provided are:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Method: authenticate_user!====&lt;br /&gt;
The &amp;lt;i&amp;gt;authenticate_user!&amp;lt;/i&amp;gt; method is a class method that can be called from a controller only. The method determines if the user has access to all or a specific set of controller actions. This method is invoked via a &amp;lt;i&amp;gt;before_filter&amp;lt;/i&amp;gt;, for example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The above statements requires the user to be logged in before they can access the controller actions. To make exceptions for accessing any actions without authentications we can update the above statement as:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before_action :authenticate_user!, except: [:show]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above example, user authentication would be required to call any actions in the controller except the &amp;lt;i&amp;gt;show&amp;lt;/i&amp;gt; action. &lt;br /&gt;
So if the &amp;lt;i&amp;gt;root&amp;lt;/i&amp;gt; in the &amp;lt;code&amp;gt;config/routes.rb&amp;lt;/code&amp;gt; field is set to obtain any view belonging to the UsersController in this case, the Sign in page will be loaded before any of the actions can be accessed. &amp;lt;br&amp;gt; Once the user is authenticate, the required action is obtained.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: current_user====&lt;br /&gt;
The &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method is used to return the model class to whom the signed in user belongs. The method returns nil if a user has not yet signed in. &lt;br /&gt;
The &amp;lt;authenticate_user!&amp;gt; will make sure that the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method would never return &amp;lt;i&amp;gt;nil&amp;lt;/i&amp;gt;. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_signed_in?====&lt;br /&gt;
Checks if the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method returns a non nil value. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: sign_in(@user) and sign_out(@user)====&lt;br /&gt;
The sign_in(@user) and the sign_out(@user) are useful to login or logout a newly created user.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_session====&lt;br /&gt;
This method returns metadata regarding the logged in user.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Modules==&lt;br /&gt;
===Database Authenticatable===&lt;br /&gt;
Ensures that the user has entered the correct password and also to encrypt and stores the password in the database when the user registers for the first time. The authentication can be done both through POST requests or HTTP Basic Authentication.&amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).valid_password?('password123')         # returns true/false &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Omniauthable===&lt;br /&gt;
Adds OmniAuth (https://github.com/intridea/omniauth) support.&amp;lt;br&amp;gt;&lt;br /&gt;
===Confirmable===&lt;br /&gt;
Sends confirmation emails to Users following successful registration. This is to prevent bot registrations. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).confirm!      # returns true unless it's already confirmed&lt;br /&gt;
User.find(1).confirmed?    # true/false&lt;br /&gt;
User.find(1).send_confirmation_instructions # manually send instructions&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Recoverable===&lt;br /&gt;
Resets the user password and sends reset instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;# resets the user password and save the record, true if valid passwords are given, otherwise false&lt;br /&gt;
User.find(1).reset_password!('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# only resets the user password, without saving the record&lt;br /&gt;
user = User.find(1)&lt;br /&gt;
user.reset_password('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# creates a new token and send it with instructions about how to reset the password&lt;br /&gt;
User.find(1).send_reset_password_instructions &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Registerable===&lt;br /&gt;
Handles signing up users through a registration process, also allowing them to edit and destroy their account.&amp;lt;br&amp;gt;&lt;br /&gt;
Helps user to register themselves and also to make changes to their login credentials including deleting their account. &lt;br /&gt;
===Rememberable=== &lt;br /&gt;
Cookie handling module to manage generating and clearing of tokens for remembering the user.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;User.find(1).remember_me!  # regenerating the token&lt;br /&gt;
User.find(1).forget_me!    # clearing the token&lt;br /&gt;
&lt;br /&gt;
# generating info to put into cookies&lt;br /&gt;
User.serialize_into_cookie(user)&lt;br /&gt;
&lt;br /&gt;
# lookup the user based on the incoming cookie information&lt;br /&gt;
User.serialize_from_cookie(cookie_string)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trackable=== &lt;br /&gt;
Tracks login details for a specific user using log in count, last log in, IP address. These details help Site admin to investigate any unusual activity.&amp;lt;br&amp;gt; &lt;br /&gt;
===Timeoutable===&lt;br /&gt;
Expires sessions that have not been active in a specified period of time.&amp;lt;br&amp;gt;&lt;br /&gt;
===Validatable===&lt;br /&gt;
Provides validations of email and password to make sure that the log in details follow a given format. These can be modified to have customized validations.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;#email_required? ⇒ Boolean protected&lt;br /&gt;
#password_required? ⇒ Boolean protected&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Lockable===&lt;br /&gt;
Locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example application ==&lt;br /&gt;
Consider an application that can be accessed by an end user and a site admin. Since the admin would have extra priviledges, partitioned access would be required. This can be implemented by representing both types of users as seperate models and having their respective controller with appropiate actions.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# All administrator controllers should inherit from this controller&lt;br /&gt;
class AdminController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :authenticate_admin!&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# All end-user controllers should inherit from this controller&lt;br /&gt;
class EndUserController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
An alternate implementaton method would be to have just one user(model) but with an &amp;lt;code&amp;gt;admin&amp;lt;/code&amp;gt; flag set to true for the admin in the model record. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationController &amp;lt; ActionController::Base&lt;br /&gt;
  before_filer :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# All administrative controllers should inherit from this controller&lt;br /&gt;
class AdminController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :ensure_admin!&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def ensure_admin!&lt;br /&gt;
    unless current_user.admin?&lt;br /&gt;
      sign_out current_user&lt;br /&gt;
&lt;br /&gt;
      redirect_to root_path&lt;br /&gt;
&lt;br /&gt;
      return false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
With this way specific controllers can have private methods. In this case, the private method checks if the user is an admin or not. Only if the user is an admin, can they access &amp;lt;i&amp;gt;AdminController&amp;lt;/i&amp;gt; actions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Rails-Devise-Pundit&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise-pundit&amp;lt;/ref&amp;gt;==&lt;br /&gt;
Pundit extends the Devise funtionailty by providing authorization services in addition to the authentication funtionality provided by Devise.  Pundit can be used to implement user roles, and limit access to pages based on user role. &lt;br /&gt;
To exemplify, Pundit can provide following features:&amp;lt;br&amp;gt;&lt;br /&gt;
* An admin can see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
* An admin can change a user’s role&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t change their role&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t see (or edit) another user’s profile&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can see (and edit) their own user profile&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Other Rails Authentication==&lt;br /&gt;
OmniAuth&amp;lt;ref&amp;gt;&amp;quot;https://github.com/intridea/omniauth&amp;quot;&amp;lt;/ref&amp;gt;: A generalized Rack framework for multiple-provider authentication.&amp;lt;br&amp;gt;&lt;br /&gt;
Authlogic&amp;lt;ref&amp;gt;https://github.com/binarylogic/authlogic&amp;lt;/ref&amp;gt;: A clean, simple, and unobtrusive ruby authentication solution.&amp;lt;br&amp;gt;&lt;br /&gt;
Restful-authentication&amp;lt;ref&amp;gt;https://github.com/technoweenie/restful-authentication&amp;lt;/ref&amp;gt;: Generates common user authentication code for Rails/Merb, with a full test/unit and rspec suite and optional Acts as State Machine support built-in.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Devise is the most popular Rails Authentication tools. It provides a full gamut of features, and can be configured to meet most requirements. Devise often interacts with Warden which does not provide helper methods, controller classes, views, configuration options and log in failure handling. All of these things are what Devise supplies. So if you need to extend or augment Devise, you may need to implement a customized Strategy class for your own.&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/ch1b_23_MS&amp;diff=94271</id>
		<title>CSC/ECE 517 Spring 2015/ch1b 23 MS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2015/ch1b_23_MS&amp;diff=94271"/>
		<updated>2015-02-18T22:49:01Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;6&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Devise&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Devise &amp;lt;ref&amp;gt;https://github.com/plataformatec/devise&amp;lt;/ref&amp;gt;''' is a Rails gem used for authenticating and managing users. &lt;br /&gt;
&lt;br /&gt;
The topic write up for this page can be found [https://docs.google.com/a/ncsu.edu/document/d/1Ay5OOUkcLMC-FH61fAm3cNvB3Uyk2hJ09vHnRgqwL-k/edit here].&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
=== Security Background===&lt;br /&gt;
Web applications are relatively easy to attack, as they are simple to understand and manipulate. The Gartner Group estimates that 75% of attacks are at the web application layer, and found out &amp;quot;that out of 300 audited sites, 97% are vulnerable to attack&amp;quot;&amp;lt;ref&amp;gt;http://www.primeon.com/press/article001.php&amp;lt;/ref&amp;gt;.Security depends on the people using the framework, and sometimes on the development method. &lt;br /&gt;
There are several ways to ensure security: Encryption, LDAP, Rails Authentication, Rails Authorization, Rails Captcha, Security Tools and Spam Detection. And devise is for Rails Authentication.&lt;br /&gt;
&lt;br /&gt;
===User Authentication Process ===&lt;br /&gt;
User Authentication is responsible for the following actions:  &lt;br /&gt;
*Signup: create a new user. This user will have to register with a username, password (which will be encrypted in the database), email, and other relevant details. &lt;br /&gt;
*Login: allow a user to sign in with her/his valid username and password. The authentication process happens by matching the username and password in the database, allowing the user access to the protected actions only if the given information matches the recorded values successfully. If not, the user will be redirected to the login page again.&lt;br /&gt;
*Access Restriction: create a session to hold the authenticated user ID after login, so navigation through additional protected actions can be done easily by just checking the userID in the current session.&lt;br /&gt;
*Logout: allow the user to sign out and set the authenticated userID in session file to nil.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Started ==&lt;br /&gt;
===Devise===&lt;br /&gt;
Devise is a flexible authentication solution for Rails helping developers save  time and effort while implementing authentication mechanisms from start. User authentication is a major component of most of the web applications, primarily to determine if the user is in fact, who it is declared to be. Devise is based on Warden&amp;lt;ref&amp;gt;https://github.com/hassox/warden/wiki&amp;lt;/ref&amp;gt;. (Customized [https://github.com/rack/rack Rack] middleware that provides authentication for rack applications). Rack can be considered a middleware between web server such as Mongreal, WEBrick and frameworks such as Rails, Sinatra. &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
To list, Rails can provide the following functionality for a Rails app:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Sign up (create account)&amp;lt;br&amp;gt;&lt;br /&gt;
* Login&amp;lt;br&amp;gt;&lt;br /&gt;
* “Forgot password?” feature&amp;lt;br&amp;gt;&lt;br /&gt;
* “Remember me” (stay logged in) feature&amp;lt;br&amp;gt;&lt;br /&gt;
* Edit account (edit user profile)&amp;lt;br&amp;gt;&lt;br /&gt;
* Validate user details while regestiring&amp;lt;br&amp;gt;&lt;br /&gt;
* Confirm user registration&lt;br /&gt;
&lt;br /&gt;
Current Version: 3.4.1&amp;lt;br&amp;gt;&lt;br /&gt;
First Release: 5 years ago&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Devise===&lt;br /&gt;
Once you have created a Rails app using the &amp;quot;rails new &amp;lt;app name&amp;gt;&amp;quot; command we first need to add a line to the &amp;quot;Gemfile&amp;quot; using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;gem 'devise'&amp;quot; &amp;gt;&amp;gt; Gemfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then install the gem using:&lt;br /&gt;
&amp;lt;pre&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
The Gem will be installed for your rails application. Then run the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:install          &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create config files.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise user              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To create model(User) class and routes and to also associate the 'User' model with 'Devise'.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:migrate                        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To run the migration and create the table with certain fields appropriate for user authentication. The result should be something like: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrating ================================&lt;br /&gt;
-- create_table(:users)&lt;br /&gt;
   -&amp;gt; 0.0178s&lt;br /&gt;
-- add_index(:users, :email, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0010s&lt;br /&gt;
-- add_index(:users, :reset_password_token, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0055s&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrated (0.0255s) =======================&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:views users      &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create the directory /app/views/users with all the devise views, such as login form, registration form .&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Methods==&lt;br /&gt;
Devise provides classes, models, views, controllers, views, helpers, routes. However, these functionality are exposed in only a small number of helper methods,   not all of these components would be required to know. Some of the important Devise helper methods provided are:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Method: authenticate_user!====&lt;br /&gt;
The &amp;lt;i&amp;gt;authenticate_user!&amp;lt;/i&amp;gt; method is a class method that can be called from a controller only. The method determines if the user has access to all or a specific set of controller actions. This method is invoked via a &amp;lt;i&amp;gt;before_filter&amp;lt;/i&amp;gt;, for example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The above statements requires the user to be logged in before they can access the controller actions. To make exceptions for accessing any actions without authentications we can update the above statement as:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before_action :authenticate_user!, except: [:show]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above example, user authentication would be required to call any actions in the controller except the &amp;lt;i&amp;gt;show&amp;lt;/i&amp;gt; action. &lt;br /&gt;
So if the &amp;lt;i&amp;gt;root&amp;lt;/i&amp;gt; in the &amp;lt;code&amp;gt;config/routes.rb&amp;lt;/code&amp;gt; field is set to obtain any view belonging to the UsersController in this case, the Sign in page will be loaded before any of the actions can be accessed. &amp;lt;br&amp;gt; Once the user is authenticate, the required action is obtained.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: current_user====&lt;br /&gt;
The &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method is used to return the model class to whom the signed in user belongs. The method returns nil if a user has not yet signed in. &lt;br /&gt;
The &amp;lt;authenticate_user!&amp;gt; will make sure that the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method would never return &amp;lt;i&amp;gt;nil&amp;lt;/i&amp;gt;. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_signed_in?====&lt;br /&gt;
Checks if the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method returns a non nil value. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: sign_in(@user) and sign_out(@user)====&lt;br /&gt;
The sign_in(@user) and the sign_out(@user) are useful to login or logout a newly created user.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_session====&lt;br /&gt;
This method returns metadata regarding the logged in user.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Modules==&lt;br /&gt;
===Database Authenticatable===&lt;br /&gt;
Ensures that the user has entered the correct password and also to encrypt and stores the password in the database when the user registers for the first time. The authentication can be done both through POST requests or HTTP Basic Authentication.&amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).valid_password?('password123')         # returns true/false &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Omniauthable===&lt;br /&gt;
Adds OmniAuth (https://github.com/intridea/omniauth) support.&amp;lt;br&amp;gt;&lt;br /&gt;
===Confirmable===&lt;br /&gt;
Sends confirmation emails to Users following successful registration. This is to prevent bot registrations. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).confirm!      # returns true unless it's already confirmed&lt;br /&gt;
User.find(1).confirmed?    # true/false&lt;br /&gt;
User.find(1).send_confirmation_instructions # manually send instructions&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Recoverable===&lt;br /&gt;
Resets the user password and sends reset instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;# resets the user password and save the record, true if valid passwords are given, otherwise false&lt;br /&gt;
User.find(1).reset_password!('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# only resets the user password, without saving the record&lt;br /&gt;
user = User.find(1)&lt;br /&gt;
user.reset_password('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# creates a new token and send it with instructions about how to reset the password&lt;br /&gt;
User.find(1).send_reset_password_instructions &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Registerable===&lt;br /&gt;
Handles signing up users through a registration process, also allowing them to edit and destroy their account.&amp;lt;br&amp;gt;&lt;br /&gt;
Helps user to register themselves and also to make changes to their login credentials including deleting their account. &lt;br /&gt;
===Rememberable=== &lt;br /&gt;
Cookie handling module to manage generating and clearing of tokens for remembering the user.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;User.find(1).remember_me!  # regenerating the token&lt;br /&gt;
User.find(1).forget_me!    # clearing the token&lt;br /&gt;
&lt;br /&gt;
# generating info to put into cookies&lt;br /&gt;
User.serialize_into_cookie(user)&lt;br /&gt;
&lt;br /&gt;
# lookup the user based on the incoming cookie information&lt;br /&gt;
User.serialize_from_cookie(cookie_string)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trackable=== &lt;br /&gt;
Tracks login details for a specific user using log in count, last log in, IP address. These details help Site admin to investigate any unusual activity.&amp;lt;br&amp;gt; &lt;br /&gt;
===Timeoutable===&lt;br /&gt;
Expires sessions that have not been active in a specified period of time.&amp;lt;br&amp;gt;&lt;br /&gt;
===Validatable===&lt;br /&gt;
Provides validations of email and password to make sure that the log in details follow a given format. These can be modified to have customized validations.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;#email_required? ⇒ Boolean protected&lt;br /&gt;
#password_required? ⇒ Boolean protected&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Lockable===&lt;br /&gt;
Locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example application ==&lt;br /&gt;
Consider an application that can be accessed by an end user and a site admin. Since the admin would have extra priviledges, partitioned access would be required. This can be implemented by representing both types of users as seperate models and having their respective controller with appropiate actions.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# All administrator controllers should inherit from this controller&lt;br /&gt;
class AdminController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :authenticate_admin!&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# All end-user controllers should inherit from this controller&lt;br /&gt;
class EndUserController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
An alternate implementaton method would be to have just one user(model) but with an &amp;lt;code&amp;gt;admin&amp;lt;/code&amp;gt; flag set to true for the admin in the model record. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationController &amp;lt; ActionController::Base&lt;br /&gt;
  before_filer :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# All administrative controllers should inherit from this controller&lt;br /&gt;
class AdminController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :ensure_admin!&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def ensure_admin!&lt;br /&gt;
    unless current_user.admin?&lt;br /&gt;
      sign_out current_user&lt;br /&gt;
&lt;br /&gt;
      redirect_to root_path&lt;br /&gt;
&lt;br /&gt;
      return false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
With this way specific controllers can have private methods. In this case, the private method checks if the user is an admin or not. Only if the user is an admin, can they access &amp;lt;i&amp;gt;AdminController&amp;lt;/i&amp;gt; actions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Rails-Devise-Pundit&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise-pundit&amp;lt;/ref&amp;gt;==&lt;br /&gt;
Pundit extends the Devise funtionailty by providing authorization services in addition to the authentication funtionality provided by Devise.  Pundit can be used to implement user roles, and limit access to pages based on user role. &lt;br /&gt;
To exemplify, Pundit can provide following features:&amp;lt;br&amp;gt;&lt;br /&gt;
* An admin can see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
* An admin can change a user’s role&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t change their role&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t see (or edit) another user’s profile&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can see (and edit) their own user profile&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Other Rails Authentication==&lt;br /&gt;
OmniAuth&amp;lt;ref&amp;gt;[&amp;quot;https://github.com/intridea/omniauth&amp;quot; asd]&amp;lt;/ref&amp;gt;: A generalized Rack framework for multiple-provider authentication.&amp;lt;br&amp;gt;&lt;br /&gt;
Authlogic&amp;lt;ref&amp;gt;https://github.com/binarylogic/authlogic&amp;lt;/ref&amp;gt;: A clean, simple, and unobtrusive ruby authentication solution.&amp;lt;br&amp;gt;&lt;br /&gt;
Restful-authentication&amp;lt;ref&amp;gt;https://github.com/technoweenie/restful-authentication&amp;lt;/ref&amp;gt;: Generates common user authentication code for Rails/Merb, with a full test/unit and rspec suite and optional Acts as State Machine support built-in.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Devise is the most popular Rails Authentication tools. It provides a full gamut of features, and can be configured to meet most requirements. Devise often interacts with Warden which does not provide helper methods, controller classes, views, configuration options and log in failure handling. All of these things are what Devise supplies. So if you need to extend or augment Devise, you may need to implement a customized Strategy class for your own.&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94246</id>
		<title>User:Mdong3</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94246"/>
		<updated>2015-02-18T20:39:07Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Other Rails Authentication */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;6&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Devise&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Devise &amp;lt;ref&amp;gt;https://github.com/plataformatec/devise&amp;lt;/ref&amp;gt;''' is a Rails gem used for authenticating and managing users. &lt;br /&gt;
&lt;br /&gt;
The topic write up for this page can be found [https://docs.google.com/a/ncsu.edu/document/d/1Ay5OOUkcLMC-FH61fAm3cNvB3Uyk2hJ09vHnRgqwL-k/edit here].&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
=== Security Background===&lt;br /&gt;
Web applications are relatively easy to attack, as they are simple to understand and manipulate. The Gartner Group estimates that 75% of attacks are at the web application layer, and found out &amp;quot;that out of 300 audited sites, 97% are vulnerable to attack&amp;quot;&amp;lt;ref&amp;gt;http://www.primeon.com/press/article001.php&amp;lt;/ref&amp;gt;.Security depends on the people using the framework, and sometimes on the development method. &lt;br /&gt;
There are several ways to ensure security: Encryption, LDAP, Rails Authentication, Rails Authorization, Rails Captcha, Security Tools and Spam Detection. And devise is for Rails Authentication.&lt;br /&gt;
&lt;br /&gt;
===User Authentication Process ===&lt;br /&gt;
User Authentication is responsible for the following actions:  &lt;br /&gt;
*Signup: create a new user. This user will have to register with a username, password (which will be encrypted in the database), email, and other relevant details. &lt;br /&gt;
*Login: allow a user to sign in with her/his valid username and password. The authentication process happens by matching the username and password in the database, allowing the user access to the protected actions only if the given information matches the recorded values successfully. If not, the user will be redirected to the login page again.&lt;br /&gt;
*Access Restriction: create a session to hold the authenticated user ID after login, so navigation through additional protected actions can be done easily by just checking the userID in the current session.&lt;br /&gt;
*Logout: allow the user to sign out and set the authenticated userID in session file to nil.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Started ==&lt;br /&gt;
===Devise===&lt;br /&gt;
Devise is a flexible authentication solution for Rails helping developers save  time and effort while implementing authentication mechanisms from start. User authentication is a major component of most of the web applications, primarily to determine if the user is in fact, who it is declared to be. Devise is based on Warden&amp;lt;ref&amp;gt;https://github.com/hassox/warden/wiki&amp;lt;/ref&amp;gt;. (Customized [https://github.com/rack/rack Rack] middleware that provides authentication for rack applications). Rack can be considered a middleware between web server such as Mongreal, WEBrick and frameworks such as Rails, Sinatra. &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
To list, Rails can provide the following functionality for a Rails app:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Sign up (create account)&amp;lt;br&amp;gt;&lt;br /&gt;
* Login&amp;lt;br&amp;gt;&lt;br /&gt;
* “Forgot password?” feature&amp;lt;br&amp;gt;&lt;br /&gt;
* “Remember me” (stay logged in) feature&amp;lt;br&amp;gt;&lt;br /&gt;
* Edit account (edit user profile)&amp;lt;br&amp;gt;&lt;br /&gt;
* Validate user details while regestiring&amp;lt;br&amp;gt;&lt;br /&gt;
* Confirm user registration&lt;br /&gt;
&lt;br /&gt;
Current Version: 3.4.1&amp;lt;br&amp;gt;&lt;br /&gt;
First Release: 5 years ago&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Devise===&lt;br /&gt;
Once you have created a Rails app using the &amp;quot;rails new &amp;lt;app name&amp;gt;&amp;quot; command we first need to add a line to the &amp;quot;Gemfile&amp;quot; using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;gem 'devise'&amp;quot; &amp;gt;&amp;gt; Gemfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then install the gem using:&lt;br /&gt;
&amp;lt;pre&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
The Gem will be installed for your rails application. Then run the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:install          &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create config files.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise user              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To create model(User) class and routes and to also associate the 'User' model with 'Devise'.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:migrate                        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To run the migration and create the table with certain fields appropriate for user authentication. The result should be something like: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrating ================================&lt;br /&gt;
-- create_table(:users)&lt;br /&gt;
   -&amp;gt; 0.0178s&lt;br /&gt;
-- add_index(:users, :email, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0010s&lt;br /&gt;
-- add_index(:users, :reset_password_token, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0055s&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrated (0.0255s) =======================&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:views users      &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create the directory /app/views/users with all the devise views, such as login form, registration form .&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Methods==&lt;br /&gt;
Devise provides classes, models, views, controllers, views, helpers, routes. However, these functionality are exposed in only a small number of helper methods,   not all of these components would be required to know. Some of the important Devise helper methods provided are:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Method: authenticate_user!====&lt;br /&gt;
The &amp;lt;i&amp;gt;authenticate_user!&amp;lt;/i&amp;gt; method is a class method that can be called from a controller only. The method determines if the user has access to all or a specific set of controller actions. This method is invoked via a &amp;lt;i&amp;gt;before_filter&amp;lt;/i&amp;gt;, for example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The above statements requires the user to be logged in before they can access the controller actions. To make exceptions for accessing any actions without authentications we can update the above statement as:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before_action :authenticate_user!, except: [:show]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above example, user authentication would be required to call any actions in the controller except the &amp;lt;i&amp;gt;show&amp;lt;/i&amp;gt; action. &lt;br /&gt;
So if the &amp;lt;i&amp;gt;root&amp;lt;/i&amp;gt; in the &amp;lt;code&amp;gt;config/routes.rb&amp;lt;/code&amp;gt; field is set to obtain any view belonging to the UsersController in this case, the Sign in page will be loaded before any of the actions can be accessed. &amp;lt;br&amp;gt; Once the user is authenticate, the required action is obtained.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: current_user====&lt;br /&gt;
The &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method is used to return the model class to whom the signed in user belongs. The method returns nil if a user has not yet signed in. &lt;br /&gt;
The &amp;lt;authenticate_user!&amp;gt; will make sure that the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method would never return &amp;lt;i&amp;gt;nil&amp;lt;/i&amp;gt;. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_signed_in?====&lt;br /&gt;
Checks if the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method returns a non nil value. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: sign_in(@user) and sign_out(@user)====&lt;br /&gt;
The sign_in(@user) and the sign_out(@user) are useful to login or logout a newly created user.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_session====&lt;br /&gt;
This method returns metadata regarding the logged in user.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Modules==&lt;br /&gt;
===Database Authenticatable===&lt;br /&gt;
Ensures that the user has entered the correct password and also to encrypt and stores the password in the database when the user registers for the first time. The authentication can be done both through POST requests or HTTP Basic Authentication.&amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).valid_password?('password123')         # returns true/false &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Omniauthable===&lt;br /&gt;
Adds OmniAuth (https://github.com/intridea/omniauth) support.&amp;lt;br&amp;gt;&lt;br /&gt;
===Confirmable===&lt;br /&gt;
Sends confirmation emails to Users following successful registration. This is to prevent bot registrations. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).confirm!      # returns true unless it's already confirmed&lt;br /&gt;
User.find(1).confirmed?    # true/false&lt;br /&gt;
User.find(1).send_confirmation_instructions # manually send instructions&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Recoverable===&lt;br /&gt;
Resets the user password and sends reset instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;# resets the user password and save the record, true if valid passwords are given, otherwise false&lt;br /&gt;
User.find(1).reset_password!('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# only resets the user password, without saving the record&lt;br /&gt;
user = User.find(1)&lt;br /&gt;
user.reset_password('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# creates a new token and send it with instructions about how to reset the password&lt;br /&gt;
User.find(1).send_reset_password_instructions &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Registerable===&lt;br /&gt;
Handles signing up users through a registration process, also allowing them to edit and destroy their account.&amp;lt;br&amp;gt;&lt;br /&gt;
Helps user to register themselves and also to make changes to their login credentials including deleting their account. &lt;br /&gt;
===Rememberable=== &lt;br /&gt;
Cookie handling module to manage generating and clearing of tokens for remembering the user.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;User.find(1).remember_me!  # regenerating the token&lt;br /&gt;
User.find(1).forget_me!    # clearing the token&lt;br /&gt;
&lt;br /&gt;
# generating info to put into cookies&lt;br /&gt;
User.serialize_into_cookie(user)&lt;br /&gt;
&lt;br /&gt;
# lookup the user based on the incoming cookie information&lt;br /&gt;
User.serialize_from_cookie(cookie_string)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trackable=== &lt;br /&gt;
Tracks login details for a specific user using log in count, last log in, IP address. These details help Site admin to investigate any unusual activity.&amp;lt;br&amp;gt; &lt;br /&gt;
===Timeoutable===&lt;br /&gt;
Expires sessions that have not been active in a specified period of time.&amp;lt;br&amp;gt;&lt;br /&gt;
===Validatable===&lt;br /&gt;
Provides validations of email and password to make sure that the log in details follow a given format. These can be modified to have customized validations.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;#email_required? ⇒ Boolean protected&lt;br /&gt;
#password_required? ⇒ Boolean protected&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Lockable===&lt;br /&gt;
Locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example application ==&lt;br /&gt;
Consider an application that can be accessed by an end user and a site admin. Since the admin would have extra priviledges, partitioned access would be required. This can be implemented by representing both types of users as seperate models and having their respective controller with appropiate actions.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# All administrator controllers should inherit from this controller&lt;br /&gt;
class AdminController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :authenticate_admin!&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# All end-user controllers should inherit from this controller&lt;br /&gt;
class EndUserController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
An alternate implementaton method would be to have just one user(model) but with an &amp;lt;code&amp;gt;admin&amp;lt;/code&amp;gt; flag set to true for the admin in the model record. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationController &amp;lt; ActionController::Base&lt;br /&gt;
  before_filer :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# All administrative controllers should inherit from this controller&lt;br /&gt;
class AdminController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :ensure_admin!&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def ensure_admin!&lt;br /&gt;
    unless current_user.admin?&lt;br /&gt;
      sign_out current_user&lt;br /&gt;
&lt;br /&gt;
      redirect_to root_path&lt;br /&gt;
&lt;br /&gt;
      return false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
With this way specific controllers can have private methods. In this case, the private method checks if the user is an admin or not. Only if the user is an admin, can they access &amp;lt;i&amp;gt;AdminController&amp;lt;/i&amp;gt; actions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Rails-Devise-Pundit&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise-pundit&amp;lt;/ref&amp;gt;==&lt;br /&gt;
Pundit extends the Devise funtionailty by providing authorization services in addition to the authentication funtionality provided by Devise.  Pundit can be used to implement user roles, and limit access to pages based on user role. &lt;br /&gt;
To exemplify, Pundit can provide following features:&amp;lt;br&amp;gt;&lt;br /&gt;
* An admin can see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
* An admin can change a user’s role&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t change their role&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t see (or edit) another user’s profile&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can see (and edit) their own user profile&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Other Rails Authentication==&lt;br /&gt;
OmniAuth&amp;lt;ref&amp;gt;[&amp;quot;https://github.com/intridea/omniauth&amp;quot; asd]&amp;lt;/ref&amp;gt;: A generalized Rack framework for multiple-provider authentication.&amp;lt;br&amp;gt;&lt;br /&gt;
Authlogic&amp;lt;ref&amp;gt;https://github.com/binarylogic/authlogic&amp;lt;/ref&amp;gt;: A clean, simple, and unobtrusive ruby authentication solution.&amp;lt;br&amp;gt;&lt;br /&gt;
Restful-authentication&amp;lt;ref&amp;gt;https://github.com/technoweenie/restful-authentication&amp;lt;/ref&amp;gt;: Generates common user authentication code for Rails/Merb, with a full test/unit and rspec suite and optional Acts as State Machine support built-in.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Devise is the most popular Rails Authentication tools. It provides a full gamut of features, and can be configured to meet most requirements. Devise often interacts with Warden which does not provide helper methods, controller classes, views, configuration options and log in failure handling. All of these things are what Devise supplies. So if you need to extend or augment Devise, you may need to implement a customized Strategy class for your own.&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94244</id>
		<title>User:Mdong3</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94244"/>
		<updated>2015-02-18T20:05:19Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;6&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Devise&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Devise &amp;lt;ref&amp;gt;https://github.com/plataformatec/devise&amp;lt;/ref&amp;gt;''' is a Rails gem used for authenticating and managing users. &lt;br /&gt;
&lt;br /&gt;
The topic write up for this page can be found [https://docs.google.com/a/ncsu.edu/document/d/1Ay5OOUkcLMC-FH61fAm3cNvB3Uyk2hJ09vHnRgqwL-k/edit here].&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
=== Security Background===&lt;br /&gt;
Web applications are relatively easy to attack, as they are simple to understand and manipulate. The Gartner Group estimates that 75% of attacks are at the web application layer, and found out &amp;quot;that out of 300 audited sites, 97% are vulnerable to attack&amp;quot;&amp;lt;ref&amp;gt;http://www.primeon.com/press/article001.php&amp;lt;/ref&amp;gt;.Security depends on the people using the framework, and sometimes on the development method. &lt;br /&gt;
There are several ways to ensure security: Encryption, LDAP, Rails Authentication, Rails Authorization, Rails Captcha, Security Tools and Spam Detection. And devise is for Rails Authentication.&lt;br /&gt;
&lt;br /&gt;
===User Authentication Process ===&lt;br /&gt;
User Authentication is responsible for the following actions:  &lt;br /&gt;
*Signup: create a new user. This user will have to register with a username, password (which will be encrypted in the database), email, and other relevant details. &lt;br /&gt;
*Login: allow a user to sign in with her/his valid username and password. The authentication process happens by matching the username and password in the database, allowing the user access to the protected actions only if the given information matches the recorded values successfully. If not, the user will be redirected to the login page again.&lt;br /&gt;
*Access Restriction: create a session to hold the authenticated user ID after login, so navigation through additional protected actions can be done easily by just checking the userID in the current session.&lt;br /&gt;
*Logout: allow the user to sign out and set the authenticated userID in session file to nil.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Started ==&lt;br /&gt;
===Devise===&lt;br /&gt;
Devise is a flexible authentication solution for Rails helping developers save  time and effort while implementing authentication mechanisms from start. User authentication is a major component of most of the web applications, primarily to determine if the user is in fact, who it is declared to be. Devise is based on Warden&amp;lt;ref&amp;gt;https://github.com/hassox/warden/wiki&amp;lt;/ref&amp;gt;. (Customized [https://github.com/rack/rack Rack] middleware that provides authentication for rack applications). Rack can be considered a middleware between web server such as Mongreal, WEBrick and frameworks such as Rails, Sinatra. &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
To list, Rails can provide the following functionality for a Rails app:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Sign up (create account)&amp;lt;br&amp;gt;&lt;br /&gt;
* Login&amp;lt;br&amp;gt;&lt;br /&gt;
* “Forgot password?” feature&amp;lt;br&amp;gt;&lt;br /&gt;
* “Remember me” (stay logged in) feature&amp;lt;br&amp;gt;&lt;br /&gt;
* Edit account (edit user profile)&amp;lt;br&amp;gt;&lt;br /&gt;
* Validate user details while regestiring&amp;lt;br&amp;gt;&lt;br /&gt;
* Confirm user registration&lt;br /&gt;
&lt;br /&gt;
Current Version: 3.4.1&amp;lt;br&amp;gt;&lt;br /&gt;
First Release: 5 years ago&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Devise===&lt;br /&gt;
Once you have created a Rails app using the &amp;quot;rails new &amp;lt;app name&amp;gt;&amp;quot; command we first need to add a line to the &amp;quot;Gemfile&amp;quot; using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;gem 'devise'&amp;quot; &amp;gt;&amp;gt; Gemfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then install the gem using:&lt;br /&gt;
&amp;lt;pre&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
The Gem will be installed for your rails application. Then run the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:install          &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create config files.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise user              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To create model(User) class and routes and to also associate the 'User' model with 'Devise'.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:migrate                        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To run the migration and create the table with certain fields appropriate for user authentication. The result should be something like: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrating ================================&lt;br /&gt;
-- create_table(:users)&lt;br /&gt;
   -&amp;gt; 0.0178s&lt;br /&gt;
-- add_index(:users, :email, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0010s&lt;br /&gt;
-- add_index(:users, :reset_password_token, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0055s&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrated (0.0255s) =======================&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:views users      &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create the directory /app/views/users with all the devise views, such as login form, registration form .&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Methods==&lt;br /&gt;
Devise provides classes, models, views, controllers, views, helpers, routes. However, these functionality are exposed in only a small number of helper methods,   not all of these components would be required to know. Some of the important Devise helper methods provided are:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Method: authenticate_user!====&lt;br /&gt;
The &amp;lt;i&amp;gt;authenticate_user!&amp;lt;/i&amp;gt; method is a class method that can be called from a controller only. The method determines if the user has access to all or a specific set of controller actions. This method is invoked via a &amp;lt;i&amp;gt;before_filter&amp;lt;/i&amp;gt;, for example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The above statements requires the user to be logged in before they can access the controller actions. To make exceptions for accessing any actions without authentications we can update the above statement as:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before_action :authenticate_user!, except: [:show]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above example, user authentication would be required to call any actions in the controller except the &amp;lt;i&amp;gt;show&amp;lt;/i&amp;gt; action. &lt;br /&gt;
So if the &amp;lt;i&amp;gt;root&amp;lt;/i&amp;gt; in the &amp;lt;code&amp;gt;config/routes.rb&amp;lt;/code&amp;gt; field is set to obtain any view belonging to the UsersController in this case, the Sign in page will be loaded before any of the actions can be accessed. &amp;lt;br&amp;gt; Once the user is authenticate, the required action is obtained.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: current_user====&lt;br /&gt;
The &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method is used to return the model class to whom the signed in user belongs. The method returns nil if a user has not yet signed in. &lt;br /&gt;
The &amp;lt;authenticate_user!&amp;gt; will make sure that the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method would never return &amp;lt;i&amp;gt;nil&amp;lt;/i&amp;gt;. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_signed_in?====&lt;br /&gt;
Checks if the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method returns a non nil value. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: sign_in(@user) and sign_out(@user)====&lt;br /&gt;
The sign_in(@user) and the sign_out(@user) are useful to login or logout a newly created user.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_session====&lt;br /&gt;
This method returns metadata regarding the logged in user.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Modules==&lt;br /&gt;
===Database Authenticatable===&lt;br /&gt;
Ensures that the user has entered the correct password and also to encrypt and stores the password in the database when the user registers for the first time. The authentication can be done both through POST requests or HTTP Basic Authentication.&amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).valid_password?('password123')         # returns true/false &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Omniauthable===&lt;br /&gt;
Adds OmniAuth (https://github.com/intridea/omniauth) support.&amp;lt;br&amp;gt;&lt;br /&gt;
===Confirmable===&lt;br /&gt;
Sends confirmation emails to Users following successful registration. This is to prevent bot registrations. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).confirm!      # returns true unless it's already confirmed&lt;br /&gt;
User.find(1).confirmed?    # true/false&lt;br /&gt;
User.find(1).send_confirmation_instructions # manually send instructions&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Recoverable===&lt;br /&gt;
Resets the user password and sends reset instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;# resets the user password and save the record, true if valid passwords are given, otherwise false&lt;br /&gt;
User.find(1).reset_password!('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# only resets the user password, without saving the record&lt;br /&gt;
user = User.find(1)&lt;br /&gt;
user.reset_password('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# creates a new token and send it with instructions about how to reset the password&lt;br /&gt;
User.find(1).send_reset_password_instructions &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Registerable===&lt;br /&gt;
Handles signing up users through a registration process, also allowing them to edit and destroy their account.&amp;lt;br&amp;gt;&lt;br /&gt;
Helps user to register themselves and also to make changes to their login credentials including deleting their account. &lt;br /&gt;
===Rememberable=== &lt;br /&gt;
Cookie handling module to manage generating and clearing of tokens for remembering the user.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;User.find(1).remember_me!  # regenerating the token&lt;br /&gt;
User.find(1).forget_me!    # clearing the token&lt;br /&gt;
&lt;br /&gt;
# generating info to put into cookies&lt;br /&gt;
User.serialize_into_cookie(user)&lt;br /&gt;
&lt;br /&gt;
# lookup the user based on the incoming cookie information&lt;br /&gt;
User.serialize_from_cookie(cookie_string)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trackable=== &lt;br /&gt;
Tracks login details for a specific user using log in count, last log in, IP address. These details help Site admin to investigate any unusual activity.&amp;lt;br&amp;gt; &lt;br /&gt;
===Timeoutable===&lt;br /&gt;
Expires sessions that have not been active in a specified period of time.&amp;lt;br&amp;gt;&lt;br /&gt;
===Validatable===&lt;br /&gt;
Provides validations of email and password to make sure that the log in details follow a given format. These can be modified to have customized validations.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;#email_required? ⇒ Boolean protected&lt;br /&gt;
#password_required? ⇒ Boolean protected&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Lockable===&lt;br /&gt;
Locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example application ==&lt;br /&gt;
Consider an application that can be accessed by an end user and a site admin. Since the admin would have extra priviledges, partitioned access would be required. This can be implemented by representing both types of users as seperate models and having their respective controller with appropiate actions.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# All administrator controllers should inherit from this controller&lt;br /&gt;
class AdminController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :authenticate_admin!&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# All end-user controllers should inherit from this controller&lt;br /&gt;
class EndUserController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
An alternate implementaton method would be to have just one user(model) but with an &amp;lt;code&amp;gt;admin&amp;lt;/code&amp;gt; flag set to true for the admin in the model record. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationController &amp;lt; ActionController::Base&lt;br /&gt;
  before_filer :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# All administrative controllers should inherit from this controller&lt;br /&gt;
class AdminController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :ensure_admin!&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def ensure_admin!&lt;br /&gt;
    unless current_user.admin?&lt;br /&gt;
      sign_out current_user&lt;br /&gt;
&lt;br /&gt;
      redirect_to root_path&lt;br /&gt;
&lt;br /&gt;
      return false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
With this way specific controllers can have private methods. In this case, the private method checks if the user is an admin or not. Only if the user is an admin, can they access &amp;lt;i&amp;gt;AdminController&amp;lt;/i&amp;gt; actions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Rails-Devise-Pundit&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise-pundit&amp;lt;/ref&amp;gt;==&lt;br /&gt;
Pundit extends the Devise funtionailty by providing authorization services in addition to the authentication funtionality provided by Devise.  Pundit can be used to implement user roles, and limit access to pages based on user role. &lt;br /&gt;
To exemplify, Pundit can provide following features:&amp;lt;br&amp;gt;&lt;br /&gt;
* An admin can see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
* An admin can change a user’s role&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t change their role&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t see (or edit) another user’s profile&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can see (and edit) their own user profile&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Other Rails Authentication==&lt;br /&gt;
OmniAuth&amp;lt;ref&amp;gt;&amp;quot;https://github.com/intridea/omniauth&amp;quot;&amp;lt;/ref&amp;gt;: A generalized Rack framework for multiple-provider authentication.&amp;lt;br&amp;gt;&lt;br /&gt;
Authlogic&amp;lt;ref&amp;gt;https://github.com/binarylogic/authlogic&amp;lt;/ref&amp;gt;: A clean, simple, and unobtrusive ruby authentication solution.&amp;lt;br&amp;gt;&lt;br /&gt;
Restful-authentication&amp;lt;ref&amp;gt;https://github.com/technoweenie/restful-authentication&amp;lt;/ref&amp;gt;: Generates common user authentication code for Rails/Merb, with a full test/unit and rspec suite and optional Acts as State Machine support built-in.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Devise is the most popular Rails Authentication tools. It provides a full gamut of features, and can be configured to meet most requirements. Devise often interacts with Warden which does not provide helper methods, controller classes, views, configuration options and log in failure handling. All of these things are what Devise supplies. So if you need to extend or augment Devise, you may need to implement a customized Strategy class for your own.&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94242</id>
		<title>User:Mdong3</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94242"/>
		<updated>2015-02-18T19:44:28Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Example application */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;6&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Devise&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Devise &amp;lt;ref&amp;gt;https://github.com/plataformatec/devise&amp;lt;/ref&amp;gt;''' is a Rails gem used for authenticating and managing users. &lt;br /&gt;
&lt;br /&gt;
The topic write up for this page can be found [https://docs.google.com/a/ncsu.edu/document/d/1Ay5OOUkcLMC-FH61fAm3cNvB3Uyk2hJ09vHnRgqwL-k/edit here].&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
=== Security Background===&lt;br /&gt;
Web applications are relatively easy to attack, as they are simple to understand and manipulate. The Gartner Group estimates that 75% of attacks are at the web application layer, and found out &amp;quot;that out of 300 audited sites, 97% are vulnerable to attack&amp;quot;&amp;lt;ref&amp;gt;http://www.primeon.com/press/article001.php&amp;lt;/ref&amp;gt;.Security depends on the people using the framework, and sometimes on the development method. &lt;br /&gt;
There are several ways to ensure security: Encryption, LDAP, Rails Authentication, Rails Authorization, Rails Captcha, Security Tools and Spam Detection. And devise is for Rails Authentication.&lt;br /&gt;
&lt;br /&gt;
===User Authentication Process ===&lt;br /&gt;
User Authentication is responsible for the following actions:  &lt;br /&gt;
*Signup: create a new user. This user will have to register with a username, password (which will be encrypted in the database), email, and other relevant details. &lt;br /&gt;
*Login: allow a user to sign in with her/his valid username and password. The authentication process happens by matching the username and password in the database, allowing the user access to the protected actions only if the given information matches the recorded values successfully. If not, the user will be redirected to the login page again.&lt;br /&gt;
*Access Restriction: create a session to hold the authenticated user ID after login, so navigation through additional protected actions can be done easily by just checking the userID in the current session.&lt;br /&gt;
*Logout: allow the user to sign out and set the authenticated userID in session file to nil.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Started ==&lt;br /&gt;
===Devise===&lt;br /&gt;
Devise is a flexible authentication solution for Rails helping developers save  time and effort while implementing authentication mechanisms from start. User authentication is a major component of most of the web applications, primarily to determine if the user is in fact, who it is declared to be. Devise is based on Warden&amp;lt;ref&amp;gt;https://github.com/hassox/warden/wiki&amp;lt;/ref&amp;gt;. (Customized [https://github.com/rack/rack Rack] middleware that provides authentication for rack applications). Rack can be considered a middleware between web server such as Mongreal, WEBrick and frameworks such as Rails, Sinatra. &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
To list, Rails can provide the following functionality for a Rails app:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Sign up (create account)&amp;lt;br&amp;gt;&lt;br /&gt;
* Login&amp;lt;br&amp;gt;&lt;br /&gt;
* “Forgot password?” feature&amp;lt;br&amp;gt;&lt;br /&gt;
* “Remember me” (stay logged in) feature&amp;lt;br&amp;gt;&lt;br /&gt;
* Edit account (edit user profile)&amp;lt;br&amp;gt;&lt;br /&gt;
* Validate user details while regestiring&amp;lt;br&amp;gt;&lt;br /&gt;
* Confirm user registration&lt;br /&gt;
&lt;br /&gt;
Current Version: 3.4.1&amp;lt;br&amp;gt;&lt;br /&gt;
First Release: 5 years ago&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Devise===&lt;br /&gt;
Once you have created a Rails app using the &amp;quot;rails new &amp;lt;app name&amp;gt;&amp;quot; command we first need to add a line to the &amp;quot;Gemfile&amp;quot; using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;gem 'devise'&amp;quot; &amp;gt;&amp;gt; Gemfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then install the gem using:&lt;br /&gt;
&amp;lt;pre&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
The Gem will be installed for your rails application. Then run the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:install          &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create config files.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise user              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To create model(User) class and routes and to also associate the 'User' model with 'Devise'.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:migrate                        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To run the migration and create the table with certain fields appropriate for user authentication. The result should be something like: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrating ================================&lt;br /&gt;
-- create_table(:users)&lt;br /&gt;
   -&amp;gt; 0.0178s&lt;br /&gt;
-- add_index(:users, :email, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0010s&lt;br /&gt;
-- add_index(:users, :reset_password_token, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0055s&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrated (0.0255s) =======================&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:views users      &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create the directory /app/views/users with all the devise views, such as login form, registration form .&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Methods==&lt;br /&gt;
Devise provides classes, models, views, controllers, views, helpers, routes. However, these functionality are exposed in only a small number of helper methods,   not all of these components would be required to know. Some of the important Devise helper methods provided are:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Method: authenticate_user!====&lt;br /&gt;
The &amp;lt;i&amp;gt;authenticate_user!&amp;lt;/i&amp;gt; method is a class method that can be called from a controller only. The method determines if the user has access to all or a specific set of controller actions. This method is invoked via a &amp;lt;i&amp;gt;before_filter&amp;lt;/i&amp;gt;, for example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The above statements requires the user to be logged in before they can access the controller actions. To make exceptions for accessing any actions without authentications we can update the above statement as:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before_action :authenticate_user!, except: [:show]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above example, user authentication would be required to call any actions in the controller except the &amp;lt;i&amp;gt;show&amp;lt;/i&amp;gt; action. &lt;br /&gt;
So if the &amp;lt;i&amp;gt;root&amp;lt;/i&amp;gt; in the &amp;lt;code&amp;gt;config/routes.rb&amp;lt;/code&amp;gt; field is set to obtain any view belonging to the UsersController in this case, the Sign in page will be loaded before any of the actions can be accessed. &amp;lt;br&amp;gt; Once the user is authenticate, the required action is obtained.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: current_user====&lt;br /&gt;
The &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method is used to return the model class to whom the signed in user belongs. The method returns nil if a user has not yet signed in. &lt;br /&gt;
The &amp;lt;authenticate_user!&amp;gt; will make sure that the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method would never return &amp;lt;i&amp;gt;nil&amp;lt;/i&amp;gt;. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_signed_in?====&lt;br /&gt;
Checks if the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method returns a non nil value. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: sign_in(@user) and sign_out(@user)====&lt;br /&gt;
The sign_in(@user) and the sign_out(@user) are useful to login or logout a newly created user.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_session====&lt;br /&gt;
This method returns metadata regarding the logged in user.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Modules==&lt;br /&gt;
===Database Authenticatable===&lt;br /&gt;
Ensures that the user has entered the correct password and also to encrypt and stores the password in the database when the user registers for the first time. The authentication can be done both through POST requests or HTTP Basic Authentication.&amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).valid_password?('password123')         # returns true/false &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Omniauthable===&lt;br /&gt;
Adds OmniAuth (https://github.com/intridea/omniauth) support.&amp;lt;br&amp;gt;&lt;br /&gt;
===Confirmable===&lt;br /&gt;
Sends confirmation emails to Users following successful registration. This is to prevent bot registrations. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).confirm!      # returns true unless it's already confirmed&lt;br /&gt;
User.find(1).confirmed?    # true/false&lt;br /&gt;
User.find(1).send_confirmation_instructions # manually send instructions&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Recoverable===&lt;br /&gt;
Resets the user password and sends reset instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;# resets the user password and save the record, true if valid passwords are given, otherwise false&lt;br /&gt;
User.find(1).reset_password!('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# only resets the user password, without saving the record&lt;br /&gt;
user = User.find(1)&lt;br /&gt;
user.reset_password('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# creates a new token and send it with instructions about how to reset the password&lt;br /&gt;
User.find(1).send_reset_password_instructions &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Registerable===&lt;br /&gt;
Handles signing up users through a registration process, also allowing them to edit and destroy their account.&amp;lt;br&amp;gt;&lt;br /&gt;
Helps user to register themselves and also to make changes to their login credentials including deleting their account. &lt;br /&gt;
===Rememberable=== &lt;br /&gt;
Cookie handling module to manage generating and clearing of tokens for remembering the user.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;User.find(1).remember_me!  # regenerating the token&lt;br /&gt;
User.find(1).forget_me!    # clearing the token&lt;br /&gt;
&lt;br /&gt;
# generating info to put into cookies&lt;br /&gt;
User.serialize_into_cookie(user)&lt;br /&gt;
&lt;br /&gt;
# lookup the user based on the incoming cookie information&lt;br /&gt;
User.serialize_from_cookie(cookie_string)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trackable=== &lt;br /&gt;
Tracks login details for a specific user using log in count, last log in, IP address. These details help Site admin to investigate any unusual activity.&amp;lt;br&amp;gt; &lt;br /&gt;
===Timeoutable===&lt;br /&gt;
Expires sessions that have not been active in a specified period of time.&amp;lt;br&amp;gt;&lt;br /&gt;
===Validatable===&lt;br /&gt;
Provides validations of email and password to make sure that the log in details follow a given format. These can be modified to have customized validations.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;#email_required? ⇒ Boolean protected&lt;br /&gt;
#password_required? ⇒ Boolean protected&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Lockable===&lt;br /&gt;
Locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example application ==&lt;br /&gt;
Consider an application that can be accessed by an end user and a site admin. Since the admin would have extra priviledges, partitioned access would be required. This can be implemented by representing both types of users as seperate models and having their respective controller with appropiate actions.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# All administrator controllers should inherit from this controller&lt;br /&gt;
class AdminController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :authenticate_admin!&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# All end-user controllers should inherit from this controller&lt;br /&gt;
class EndUserController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
An alternate implementaton method would be to have just one user(model) but with an &amp;lt;code&amp;gt;admin&amp;lt;/code&amp;gt; flag set to true for the admin in the model record. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationController &amp;lt; ActionController::Base&lt;br /&gt;
  before_filer :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# All administrative controllers should inherit from this controller&lt;br /&gt;
class AdminController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :ensure_admin!&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def ensure_admin!&lt;br /&gt;
    unless current_user.admin?&lt;br /&gt;
      sign_out current_user&lt;br /&gt;
&lt;br /&gt;
      redirect_to root_path&lt;br /&gt;
&lt;br /&gt;
      return false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
With this way specific controllers can have private methods. In this case, the private method checks if the user is an admin or not. Only if the user is an admin, can they access &amp;lt;i&amp;gt;AdminController&amp;lt;/i&amp;gt; actions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Rails-Devise-Pundit&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise-pundit&amp;lt;/ref&amp;gt;==&lt;br /&gt;
Pundit extends the Devise funtionailty by providing authorization services in addition to the authentication funtionality provided by Devise.  Pundit can be used to implement user roles, and limit access to pages based on user role. &lt;br /&gt;
To exemplify, Pundit can provide following features:&amp;lt;br&amp;gt;&lt;br /&gt;
* An admin can see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
* An admin can change a user’s role&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t change their role&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t see (or edit) another user’s profile&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can see (and edit) their own user profile&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Other Rails Authentication==&lt;br /&gt;
OmniAuth&amp;lt;ref&amp;gt;https://github.com/intridea/omniauth&amp;lt;/ref&amp;gt;: A generalized Rack framework for multiple-provider authentication.&amp;lt;br&amp;gt;&lt;br /&gt;
Authlogic&amp;lt;ref&amp;gt;https://github.com/binarylogic/authlogic&amp;lt;/ref&amp;gt;: A clean, simple, and unobtrusive ruby authentication solution.&amp;lt;br&amp;gt;&lt;br /&gt;
Restful-authentication&amp;lt;ref&amp;gt;https://github.com/technoweenie/restful-authentication&amp;lt;/ref&amp;gt;: Generates common user authentication code for Rails/Merb, with a full test/unit and rspec suite and optional Acts as State Machine support built-in.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Devise is the most popular Rails Authentication tools. It provides a full gamut of features, and can be configured to meet most requirements. Devise often interacts with Warden which does not provide helper methods, controller classes, views, configuration options and log in failure handling. All of these things are what Devise supplies. So if you need to extend or augment Devise, you may need to implement a customized Strategy class for your own.&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94241</id>
		<title>User:Mdong3</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94241"/>
		<updated>2015-02-18T19:43:46Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Lockable */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;6&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Devise&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Devise &amp;lt;ref&amp;gt;https://github.com/plataformatec/devise&amp;lt;/ref&amp;gt;''' is a Rails gem used for authenticating and managing users. &lt;br /&gt;
&lt;br /&gt;
The topic write up for this page can be found [https://docs.google.com/a/ncsu.edu/document/d/1Ay5OOUkcLMC-FH61fAm3cNvB3Uyk2hJ09vHnRgqwL-k/edit here].&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
=== Security Background===&lt;br /&gt;
Web applications are relatively easy to attack, as they are simple to understand and manipulate. The Gartner Group estimates that 75% of attacks are at the web application layer, and found out &amp;quot;that out of 300 audited sites, 97% are vulnerable to attack&amp;quot;&amp;lt;ref&amp;gt;http://www.primeon.com/press/article001.php&amp;lt;/ref&amp;gt;.Security depends on the people using the framework, and sometimes on the development method. &lt;br /&gt;
There are several ways to ensure security: Encryption, LDAP, Rails Authentication, Rails Authorization, Rails Captcha, Security Tools and Spam Detection. And devise is for Rails Authentication.&lt;br /&gt;
&lt;br /&gt;
===User Authentication Process ===&lt;br /&gt;
User Authentication is responsible for the following actions:  &lt;br /&gt;
*Signup: create a new user. This user will have to register with a username, password (which will be encrypted in the database), email, and other relevant details. &lt;br /&gt;
*Login: allow a user to sign in with her/his valid username and password. The authentication process happens by matching the username and password in the database, allowing the user access to the protected actions only if the given information matches the recorded values successfully. If not, the user will be redirected to the login page again.&lt;br /&gt;
*Access Restriction: create a session to hold the authenticated user ID after login, so navigation through additional protected actions can be done easily by just checking the userID in the current session.&lt;br /&gt;
*Logout: allow the user to sign out and set the authenticated userID in session file to nil.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Started ==&lt;br /&gt;
===Devise===&lt;br /&gt;
Devise is a flexible authentication solution for Rails helping developers save  time and effort while implementing authentication mechanisms from start. User authentication is a major component of most of the web applications, primarily to determine if the user is in fact, who it is declared to be. Devise is based on Warden&amp;lt;ref&amp;gt;https://github.com/hassox/warden/wiki&amp;lt;/ref&amp;gt;. (Customized [https://github.com/rack/rack Rack] middleware that provides authentication for rack applications). Rack can be considered a middleware between web server such as Mongreal, WEBrick and frameworks such as Rails, Sinatra. &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
To list, Rails can provide the following functionality for a Rails app:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Sign up (create account)&amp;lt;br&amp;gt;&lt;br /&gt;
* Login&amp;lt;br&amp;gt;&lt;br /&gt;
* “Forgot password?” feature&amp;lt;br&amp;gt;&lt;br /&gt;
* “Remember me” (stay logged in) feature&amp;lt;br&amp;gt;&lt;br /&gt;
* Edit account (edit user profile)&amp;lt;br&amp;gt;&lt;br /&gt;
* Validate user details while regestiring&amp;lt;br&amp;gt;&lt;br /&gt;
* Confirm user registration&lt;br /&gt;
&lt;br /&gt;
Current Version: 3.4.1&amp;lt;br&amp;gt;&lt;br /&gt;
First Release: 5 years ago&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Devise===&lt;br /&gt;
Once you have created a Rails app using the &amp;quot;rails new &amp;lt;app name&amp;gt;&amp;quot; command we first need to add a line to the &amp;quot;Gemfile&amp;quot; using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;gem 'devise'&amp;quot; &amp;gt;&amp;gt; Gemfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then install the gem using:&lt;br /&gt;
&amp;lt;pre&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
The Gem will be installed for your rails application. Then run the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:install          &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create config files.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise user              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To create model(User) class and routes and to also associate the 'User' model with 'Devise'.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:migrate                        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To run the migration and create the table with certain fields appropriate for user authentication. The result should be something like: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrating ================================&lt;br /&gt;
-- create_table(:users)&lt;br /&gt;
   -&amp;gt; 0.0178s&lt;br /&gt;
-- add_index(:users, :email, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0010s&lt;br /&gt;
-- add_index(:users, :reset_password_token, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0055s&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrated (0.0255s) =======================&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:views users      &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create the directory /app/views/users with all the devise views, such as login form, registration form .&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Methods==&lt;br /&gt;
Devise provides classes, models, views, controllers, views, helpers, routes. However, these functionality are exposed in only a small number of helper methods,   not all of these components would be required to know. Some of the important Devise helper methods provided are:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Method: authenticate_user!====&lt;br /&gt;
The &amp;lt;i&amp;gt;authenticate_user!&amp;lt;/i&amp;gt; method is a class method that can be called from a controller only. The method determines if the user has access to all or a specific set of controller actions. This method is invoked via a &amp;lt;i&amp;gt;before_filter&amp;lt;/i&amp;gt;, for example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The above statements requires the user to be logged in before they can access the controller actions. To make exceptions for accessing any actions without authentications we can update the above statement as:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before_action :authenticate_user!, except: [:show]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above example, user authentication would be required to call any actions in the controller except the &amp;lt;i&amp;gt;show&amp;lt;/i&amp;gt; action. &lt;br /&gt;
So if the &amp;lt;i&amp;gt;root&amp;lt;/i&amp;gt; in the &amp;lt;code&amp;gt;config/routes.rb&amp;lt;/code&amp;gt; field is set to obtain any view belonging to the UsersController in this case, the Sign in page will be loaded before any of the actions can be accessed. &amp;lt;br&amp;gt; Once the user is authenticate, the required action is obtained.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: current_user====&lt;br /&gt;
The &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method is used to return the model class to whom the signed in user belongs. The method returns nil if a user has not yet signed in. &lt;br /&gt;
The &amp;lt;authenticate_user!&amp;gt; will make sure that the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method would never return &amp;lt;i&amp;gt;nil&amp;lt;/i&amp;gt;. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_signed_in?====&lt;br /&gt;
Checks if the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method returns a non nil value. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: sign_in(@user) and sign_out(@user)====&lt;br /&gt;
The sign_in(@user) and the sign_out(@user) are useful to login or logout a newly created user.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_session====&lt;br /&gt;
This method returns metadata regarding the logged in user.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Modules==&lt;br /&gt;
===Database Authenticatable===&lt;br /&gt;
Ensures that the user has entered the correct password and also to encrypt and stores the password in the database when the user registers for the first time. The authentication can be done both through POST requests or HTTP Basic Authentication.&amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).valid_password?('password123')         # returns true/false &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Omniauthable===&lt;br /&gt;
Adds OmniAuth (https://github.com/intridea/omniauth) support.&amp;lt;br&amp;gt;&lt;br /&gt;
===Confirmable===&lt;br /&gt;
Sends confirmation emails to Users following successful registration. This is to prevent bot registrations. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).confirm!      # returns true unless it's already confirmed&lt;br /&gt;
User.find(1).confirmed?    # true/false&lt;br /&gt;
User.find(1).send_confirmation_instructions # manually send instructions&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Recoverable===&lt;br /&gt;
Resets the user password and sends reset instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;# resets the user password and save the record, true if valid passwords are given, otherwise false&lt;br /&gt;
User.find(1).reset_password!('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# only resets the user password, without saving the record&lt;br /&gt;
user = User.find(1)&lt;br /&gt;
user.reset_password('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# creates a new token and send it with instructions about how to reset the password&lt;br /&gt;
User.find(1).send_reset_password_instructions &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Registerable===&lt;br /&gt;
Handles signing up users through a registration process, also allowing them to edit and destroy their account.&amp;lt;br&amp;gt;&lt;br /&gt;
Helps user to register themselves and also to make changes to their login credentials including deleting their account. &lt;br /&gt;
===Rememberable=== &lt;br /&gt;
Cookie handling module to manage generating and clearing of tokens for remembering the user.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;User.find(1).remember_me!  # regenerating the token&lt;br /&gt;
User.find(1).forget_me!    # clearing the token&lt;br /&gt;
&lt;br /&gt;
# generating info to put into cookies&lt;br /&gt;
User.serialize_into_cookie(user)&lt;br /&gt;
&lt;br /&gt;
# lookup the user based on the incoming cookie information&lt;br /&gt;
User.serialize_from_cookie(cookie_string)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trackable=== &lt;br /&gt;
Tracks login details for a specific user using log in count, last log in, IP address. These details help Site admin to investigate any unusual activity.&amp;lt;br&amp;gt; &lt;br /&gt;
===Timeoutable===&lt;br /&gt;
Expires sessions that have not been active in a specified period of time.&amp;lt;br&amp;gt;&lt;br /&gt;
===Validatable===&lt;br /&gt;
Provides validations of email and password to make sure that the log in details follow a given format. These can be modified to have customized validations.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;#email_required? ⇒ Boolean protected&lt;br /&gt;
#password_required? ⇒ Boolean protected&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Lockable===&lt;br /&gt;
Locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example application ==&lt;br /&gt;
Consider an application that can be accessed by an end user and a site admin. Since the admin would have extra priviledges, partitioned access would be required. This can be implemented by representing both types of users as seperate models and having their respective controller with appropiate actions.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# All administrator controllers should inherit from this controller&lt;br /&gt;
class AdminController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :authenticate_admin!&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# All end-user controllers should inherit from this controller&lt;br /&gt;
class EndUserController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
An alternate implementaton method would be to have just one user(model) but with an &amp;lt;code&amp;gt;admin&amp;lt;/code&amp;gt; flag set to true for the admin in the model record. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationController &amp;lt; ActionController::Base&lt;br /&gt;
  before_filer :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# All administrative controllers should inherit from this controller&lt;br /&gt;
class AdminController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :ensure_admin!&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def ensure_admin!&lt;br /&gt;
    unless current_user.admin?&lt;br /&gt;
      sign_out current_user&lt;br /&gt;
&lt;br /&gt;
      redirect_to root_path&lt;br /&gt;
&lt;br /&gt;
      return false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
With this way specific controllers can have private methods. In this case, the private method checks if the user is an admin or not. Only if the user is an admin, can they access &amp;lt;i&amp;gt;AdminController&amp;lt;/i&amp;gt; actions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Rails-Devise-Pundit&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise-pundit&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Pundit extends the Devise funtionailty by providing authorization services in addition to the authentication funtionality provided by Devise.  Pundit can be used to implement user roles, and limit access to pages based on user role. &lt;br /&gt;
To exemplify, Pundit can provide following features:&amp;lt;br&amp;gt;&lt;br /&gt;
* An admin can see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
* An admin can change a user’s role&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t change their role&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t see (or edit) another user’s profile&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can see (and edit) their own user profile&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Other Rails Authentication==&lt;br /&gt;
OmniAuth&amp;lt;ref&amp;gt;https://github.com/intridea/omniauth&amp;lt;/ref&amp;gt;: A generalized Rack framework for multiple-provider authentication.&amp;lt;br&amp;gt;&lt;br /&gt;
Authlogic&amp;lt;ref&amp;gt;https://github.com/binarylogic/authlogic&amp;lt;/ref&amp;gt;: A clean, simple, and unobtrusive ruby authentication solution.&amp;lt;br&amp;gt;&lt;br /&gt;
Restful-authentication&amp;lt;ref&amp;gt;https://github.com/technoweenie/restful-authentication&amp;lt;/ref&amp;gt;: Generates common user authentication code for Rails/Merb, with a full test/unit and rspec suite and optional Acts as State Machine support built-in.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Devise is the most popular Rails Authentication tools. It provides a full gamut of features, and can be configured to meet most requirements. Devise often interacts with Warden which does not provide helper methods, controller classes, views, configuration options and log in failure handling. All of these things are what Devise supplies. So if you need to extend or augment Devise, you may need to implement a customized Strategy class for your own.&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94240</id>
		<title>User:Mdong3</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94240"/>
		<updated>2015-02-18T19:43:01Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Rails-Devise-Pundithttps://github.com/RailsApps/rails-devise-pundit */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;6&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Devise&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Devise &amp;lt;ref&amp;gt;https://github.com/plataformatec/devise&amp;lt;/ref&amp;gt;''' is a Rails gem used for authenticating and managing users. &lt;br /&gt;
&lt;br /&gt;
The topic write up for this page can be found [https://docs.google.com/a/ncsu.edu/document/d/1Ay5OOUkcLMC-FH61fAm3cNvB3Uyk2hJ09vHnRgqwL-k/edit here].&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
=== Security Background===&lt;br /&gt;
Web applications are relatively easy to attack, as they are simple to understand and manipulate. The Gartner Group estimates that 75% of attacks are at the web application layer, and found out &amp;quot;that out of 300 audited sites, 97% are vulnerable to attack&amp;quot;&amp;lt;ref&amp;gt;http://www.primeon.com/press/article001.php&amp;lt;/ref&amp;gt;.Security depends on the people using the framework, and sometimes on the development method. &lt;br /&gt;
There are several ways to ensure security: Encryption, LDAP, Rails Authentication, Rails Authorization, Rails Captcha, Security Tools and Spam Detection. And devise is for Rails Authentication.&lt;br /&gt;
&lt;br /&gt;
===User Authentication Process ===&lt;br /&gt;
User Authentication is responsible for the following actions:  &lt;br /&gt;
*Signup: create a new user. This user will have to register with a username, password (which will be encrypted in the database), email, and other relevant details. &lt;br /&gt;
*Login: allow a user to sign in with her/his valid username and password. The authentication process happens by matching the username and password in the database, allowing the user access to the protected actions only if the given information matches the recorded values successfully. If not, the user will be redirected to the login page again.&lt;br /&gt;
*Access Restriction: create a session to hold the authenticated user ID after login, so navigation through additional protected actions can be done easily by just checking the userID in the current session.&lt;br /&gt;
*Logout: allow the user to sign out and set the authenticated userID in session file to nil.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Started ==&lt;br /&gt;
===Devise===&lt;br /&gt;
Devise is a flexible authentication solution for Rails helping developers save  time and effort while implementing authentication mechanisms from start. User authentication is a major component of most of the web applications, primarily to determine if the user is in fact, who it is declared to be. Devise is based on Warden&amp;lt;ref&amp;gt;https://github.com/hassox/warden/wiki&amp;lt;/ref&amp;gt;. (Customized [https://github.com/rack/rack Rack] middleware that provides authentication for rack applications). Rack can be considered a middleware between web server such as Mongreal, WEBrick and frameworks such as Rails, Sinatra. &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
To list, Rails can provide the following functionality for a Rails app:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Sign up (create account)&amp;lt;br&amp;gt;&lt;br /&gt;
* Login&amp;lt;br&amp;gt;&lt;br /&gt;
* “Forgot password?” feature&amp;lt;br&amp;gt;&lt;br /&gt;
* “Remember me” (stay logged in) feature&amp;lt;br&amp;gt;&lt;br /&gt;
* Edit account (edit user profile)&amp;lt;br&amp;gt;&lt;br /&gt;
* Validate user details while regestiring&amp;lt;br&amp;gt;&lt;br /&gt;
* Confirm user registration&lt;br /&gt;
&lt;br /&gt;
Current Version: 3.4.1&amp;lt;br&amp;gt;&lt;br /&gt;
First Release: 5 years ago&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Devise===&lt;br /&gt;
Once you have created a Rails app using the &amp;quot;rails new &amp;lt;app name&amp;gt;&amp;quot; command we first need to add a line to the &amp;quot;Gemfile&amp;quot; using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;gem 'devise'&amp;quot; &amp;gt;&amp;gt; Gemfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then install the gem using:&lt;br /&gt;
&amp;lt;pre&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
The Gem will be installed for your rails application. Then run the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:install          &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create config files.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise user              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To create model(User) class and routes and to also associate the 'User' model with 'Devise'.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:migrate                        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To run the migration and create the table with certain fields appropriate for user authentication. The result should be something like: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrating ================================&lt;br /&gt;
-- create_table(:users)&lt;br /&gt;
   -&amp;gt; 0.0178s&lt;br /&gt;
-- add_index(:users, :email, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0010s&lt;br /&gt;
-- add_index(:users, :reset_password_token, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0055s&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrated (0.0255s) =======================&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:views users      &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create the directory /app/views/users with all the devise views, such as login form, registration form .&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Methods==&lt;br /&gt;
Devise provides classes, models, views, controllers, views, helpers, routes. However, these functionality are exposed in only a small number of helper methods,   not all of these components would be required to know. Some of the important Devise helper methods provided are:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Method: authenticate_user!====&lt;br /&gt;
The &amp;lt;i&amp;gt;authenticate_user!&amp;lt;/i&amp;gt; method is a class method that can be called from a controller only. The method determines if the user has access to all or a specific set of controller actions. This method is invoked via a &amp;lt;i&amp;gt;before_filter&amp;lt;/i&amp;gt;, for example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The above statements requires the user to be logged in before they can access the controller actions. To make exceptions for accessing any actions without authentications we can update the above statement as:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before_action :authenticate_user!, except: [:show]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above example, user authentication would be required to call any actions in the controller except the &amp;lt;i&amp;gt;show&amp;lt;/i&amp;gt; action. &lt;br /&gt;
So if the &amp;lt;i&amp;gt;root&amp;lt;/i&amp;gt; in the &amp;lt;code&amp;gt;config/routes.rb&amp;lt;/code&amp;gt; field is set to obtain any view belonging to the UsersController in this case, the Sign in page will be loaded before any of the actions can be accessed. &amp;lt;br&amp;gt; Once the user is authenticate, the required action is obtained.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: current_user====&lt;br /&gt;
The &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method is used to return the model class to whom the signed in user belongs. The method returns nil if a user has not yet signed in. &lt;br /&gt;
The &amp;lt;authenticate_user!&amp;gt; will make sure that the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method would never return &amp;lt;i&amp;gt;nil&amp;lt;/i&amp;gt;. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_signed_in?====&lt;br /&gt;
Checks if the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method returns a non nil value. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: sign_in(@user) and sign_out(@user)====&lt;br /&gt;
The sign_in(@user) and the sign_out(@user) are useful to login or logout a newly created user.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_session====&lt;br /&gt;
This method returns metadata regarding the logged in user.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Modules==&lt;br /&gt;
===Database Authenticatable===&lt;br /&gt;
Ensures that the user has entered the correct password and also to encrypt and stores the password in the database when the user registers for the first time. The authentication can be done both through POST requests or HTTP Basic Authentication.&amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).valid_password?('password123')         # returns true/false &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Omniauthable===&lt;br /&gt;
Adds OmniAuth (https://github.com/intridea/omniauth) support.&amp;lt;br&amp;gt;&lt;br /&gt;
===Confirmable===&lt;br /&gt;
Sends confirmation emails to Users following successful registration. This is to prevent bot registrations. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).confirm!      # returns true unless it's already confirmed&lt;br /&gt;
User.find(1).confirmed?    # true/false&lt;br /&gt;
User.find(1).send_confirmation_instructions # manually send instructions&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Recoverable===&lt;br /&gt;
Resets the user password and sends reset instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;# resets the user password and save the record, true if valid passwords are given, otherwise false&lt;br /&gt;
User.find(1).reset_password!('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# only resets the user password, without saving the record&lt;br /&gt;
user = User.find(1)&lt;br /&gt;
user.reset_password('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# creates a new token and send it with instructions about how to reset the password&lt;br /&gt;
User.find(1).send_reset_password_instructions &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Registerable===&lt;br /&gt;
Handles signing up users through a registration process, also allowing them to edit and destroy their account.&amp;lt;br&amp;gt;&lt;br /&gt;
Helps user to register themselves and also to make changes to their login credentials including deleting their account. &lt;br /&gt;
===Rememberable=== &lt;br /&gt;
Cookie handling module to manage generating and clearing of tokens for remembering the user.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;User.find(1).remember_me!  # regenerating the token&lt;br /&gt;
User.find(1).forget_me!    # clearing the token&lt;br /&gt;
&lt;br /&gt;
# generating info to put into cookies&lt;br /&gt;
User.serialize_into_cookie(user)&lt;br /&gt;
&lt;br /&gt;
# lookup the user based on the incoming cookie information&lt;br /&gt;
User.serialize_from_cookie(cookie_string)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trackable=== &lt;br /&gt;
Tracks login details for a specific user using log in count, last log in, IP address. These details help Site admin to investigate any unusual activity.&amp;lt;br&amp;gt; &lt;br /&gt;
===Timeoutable===&lt;br /&gt;
Expires sessions that have not been active in a specified period of time.&amp;lt;br&amp;gt;&lt;br /&gt;
===Validatable===&lt;br /&gt;
Provides validations of email and password to make sure that the log in details follow a given format. These can be modified to have customized validations.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;#email_required? ⇒ Boolean protected&lt;br /&gt;
#password_required? ⇒ Boolean protected&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Lockable===&lt;br /&gt;
Locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example application ==&lt;br /&gt;
Consider an application that can be accessed by an end user and a site admin. Since the admin would have extra priviledges, partitioned access would be required. This can be implemented by representing both types of users as seperate models and having their respective controller with appropiate actions.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# All administrator controllers should inherit from this controller&lt;br /&gt;
class AdminController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :authenticate_admin!&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# All end-user controllers should inherit from this controller&lt;br /&gt;
class EndUserController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
An alternate implementaton method would be to have just one user(model) but with an &amp;lt;code&amp;gt;admin&amp;lt;/code&amp;gt; flag set to true for the admin in the model record. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationController &amp;lt; ActionController::Base&lt;br /&gt;
  before_filer :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# All administrative controllers should inherit from this controller&lt;br /&gt;
class AdminController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :ensure_admin!&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def ensure_admin!&lt;br /&gt;
    unless current_user.admin?&lt;br /&gt;
      sign_out current_user&lt;br /&gt;
&lt;br /&gt;
      redirect_to root_path&lt;br /&gt;
&lt;br /&gt;
      return false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
With this way specific controllers can have private methods. In this case, the private method checks if the user is an admin or not. Only if the user is an admin, can they access &amp;lt;i&amp;gt;AdminController&amp;lt;/i&amp;gt; actions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Rails-Devise-Pundit&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise-pundit&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Pundit extends the Devise funtionailty by providing authorization services in addition to the authentication funtionality provided by Devise.  Pundit can be used to implement user roles, and limit access to pages based on user role. &lt;br /&gt;
To exemplify, Pundit can provide following features:&amp;lt;br&amp;gt;&lt;br /&gt;
* An admin can see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
* An admin can change a user’s role&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t change their role&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t see (or edit) another user’s profile&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can see (and edit) their own user profile&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Other Rails Authentication==&lt;br /&gt;
OmniAuth&amp;lt;ref&amp;gt;https://github.com/intridea/omniauth&amp;lt;/ref&amp;gt;: A generalized Rack framework for multiple-provider authentication.&amp;lt;br&amp;gt;&lt;br /&gt;
Authlogic&amp;lt;ref&amp;gt;https://github.com/binarylogic/authlogic&amp;lt;/ref&amp;gt;: A clean, simple, and unobtrusive ruby authentication solution.&amp;lt;br&amp;gt;&lt;br /&gt;
Restful-authentication&amp;lt;ref&amp;gt;https://github.com/technoweenie/restful-authentication&amp;lt;/ref&amp;gt;: Generates common user authentication code for Rails/Merb, with a full test/unit and rspec suite and optional Acts as State Machine support built-in.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Devise is the most popular Rails Authentication tools. It provides a full gamut of features, and can be configured to meet most requirements. Devise often interacts with Warden which does not provide helper methods, controller classes, views, configuration options and log in failure handling. All of these things are what Devise supplies. So if you need to extend or augment Devise, you may need to implement a customized Strategy class for your own.&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94239</id>
		<title>User:Mdong3</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94239"/>
		<updated>2015-02-18T19:42:05Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Example applications */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;6&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Devise&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Devise &amp;lt;ref&amp;gt;https://github.com/plataformatec/devise&amp;lt;/ref&amp;gt;''' is a Rails gem used for authenticating and managing users. &lt;br /&gt;
&lt;br /&gt;
The topic write up for this page can be found [https://docs.google.com/a/ncsu.edu/document/d/1Ay5OOUkcLMC-FH61fAm3cNvB3Uyk2hJ09vHnRgqwL-k/edit here].&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
=== Security Background===&lt;br /&gt;
Web applications are relatively easy to attack, as they are simple to understand and manipulate. The Gartner Group estimates that 75% of attacks are at the web application layer, and found out &amp;quot;that out of 300 audited sites, 97% are vulnerable to attack&amp;quot;&amp;lt;ref&amp;gt;http://www.primeon.com/press/article001.php&amp;lt;/ref&amp;gt;.Security depends on the people using the framework, and sometimes on the development method. &lt;br /&gt;
There are several ways to ensure security: Encryption, LDAP, Rails Authentication, Rails Authorization, Rails Captcha, Security Tools and Spam Detection. And devise is for Rails Authentication.&lt;br /&gt;
&lt;br /&gt;
===User Authentication Process ===&lt;br /&gt;
User Authentication is responsible for the following actions:  &lt;br /&gt;
*Signup: create a new user. This user will have to register with a username, password (which will be encrypted in the database), email, and other relevant details. &lt;br /&gt;
*Login: allow a user to sign in with her/his valid username and password. The authentication process happens by matching the username and password in the database, allowing the user access to the protected actions only if the given information matches the recorded values successfully. If not, the user will be redirected to the login page again.&lt;br /&gt;
*Access Restriction: create a session to hold the authenticated user ID after login, so navigation through additional protected actions can be done easily by just checking the userID in the current session.&lt;br /&gt;
*Logout: allow the user to sign out and set the authenticated userID in session file to nil.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Started ==&lt;br /&gt;
===Devise===&lt;br /&gt;
Devise is a flexible authentication solution for Rails helping developers save  time and effort while implementing authentication mechanisms from start. User authentication is a major component of most of the web applications, primarily to determine if the user is in fact, who it is declared to be. Devise is based on Warden&amp;lt;ref&amp;gt;https://github.com/hassox/warden/wiki&amp;lt;/ref&amp;gt;. (Customized [https://github.com/rack/rack Rack] middleware that provides authentication for rack applications). Rack can be considered a middleware between web server such as Mongreal, WEBrick and frameworks such as Rails, Sinatra. &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
To list, Rails can provide the following functionality for a Rails app:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Sign up (create account)&amp;lt;br&amp;gt;&lt;br /&gt;
* Login&amp;lt;br&amp;gt;&lt;br /&gt;
* “Forgot password?” feature&amp;lt;br&amp;gt;&lt;br /&gt;
* “Remember me” (stay logged in) feature&amp;lt;br&amp;gt;&lt;br /&gt;
* Edit account (edit user profile)&amp;lt;br&amp;gt;&lt;br /&gt;
* Validate user details while regestiring&amp;lt;br&amp;gt;&lt;br /&gt;
* Confirm user registration&lt;br /&gt;
&lt;br /&gt;
Current Version: 3.4.1&amp;lt;br&amp;gt;&lt;br /&gt;
First Release: 5 years ago&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Devise===&lt;br /&gt;
Once you have created a Rails app using the &amp;quot;rails new &amp;lt;app name&amp;gt;&amp;quot; command we first need to add a line to the &amp;quot;Gemfile&amp;quot; using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;gem 'devise'&amp;quot; &amp;gt;&amp;gt; Gemfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then install the gem using:&lt;br /&gt;
&amp;lt;pre&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
The Gem will be installed for your rails application. Then run the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:install          &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create config files.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise user              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To create model(User) class and routes and to also associate the 'User' model with 'Devise'.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:migrate                        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To run the migration and create the table with certain fields appropriate for user authentication. The result should be something like: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrating ================================&lt;br /&gt;
-- create_table(:users)&lt;br /&gt;
   -&amp;gt; 0.0178s&lt;br /&gt;
-- add_index(:users, :email, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0010s&lt;br /&gt;
-- add_index(:users, :reset_password_token, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0055s&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrated (0.0255s) =======================&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:views users      &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create the directory /app/views/users with all the devise views, such as login form, registration form .&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Methods==&lt;br /&gt;
Devise provides classes, models, views, controllers, views, helpers, routes. However, these functionality are exposed in only a small number of helper methods,   not all of these components would be required to know. Some of the important Devise helper methods provided are:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Method: authenticate_user!====&lt;br /&gt;
The &amp;lt;i&amp;gt;authenticate_user!&amp;lt;/i&amp;gt; method is a class method that can be called from a controller only. The method determines if the user has access to all or a specific set of controller actions. This method is invoked via a &amp;lt;i&amp;gt;before_filter&amp;lt;/i&amp;gt;, for example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The above statements requires the user to be logged in before they can access the controller actions. To make exceptions for accessing any actions without authentications we can update the above statement as:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before_action :authenticate_user!, except: [:show]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above example, user authentication would be required to call any actions in the controller except the &amp;lt;i&amp;gt;show&amp;lt;/i&amp;gt; action. &lt;br /&gt;
So if the &amp;lt;i&amp;gt;root&amp;lt;/i&amp;gt; in the &amp;lt;code&amp;gt;config/routes.rb&amp;lt;/code&amp;gt; field is set to obtain any view belonging to the UsersController in this case, the Sign in page will be loaded before any of the actions can be accessed. &amp;lt;br&amp;gt; Once the user is authenticate, the required action is obtained.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: current_user====&lt;br /&gt;
The &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method is used to return the model class to whom the signed in user belongs. The method returns nil if a user has not yet signed in. &lt;br /&gt;
The &amp;lt;authenticate_user!&amp;gt; will make sure that the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method would never return &amp;lt;i&amp;gt;nil&amp;lt;/i&amp;gt;. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_signed_in?====&lt;br /&gt;
Checks if the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method returns a non nil value. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: sign_in(@user) and sign_out(@user)====&lt;br /&gt;
The sign_in(@user) and the sign_out(@user) are useful to login or logout a newly created user.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_session====&lt;br /&gt;
This method returns metadata regarding the logged in user.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Modules==&lt;br /&gt;
===Database Authenticatable===&lt;br /&gt;
Ensures that the user has entered the correct password and also to encrypt and stores the password in the database when the user registers for the first time. The authentication can be done both through POST requests or HTTP Basic Authentication.&amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).valid_password?('password123')         # returns true/false &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Omniauthable===&lt;br /&gt;
Adds OmniAuth (https://github.com/intridea/omniauth) support.&amp;lt;br&amp;gt;&lt;br /&gt;
===Confirmable===&lt;br /&gt;
Sends confirmation emails to Users following successful registration. This is to prevent bot registrations. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).confirm!      # returns true unless it's already confirmed&lt;br /&gt;
User.find(1).confirmed?    # true/false&lt;br /&gt;
User.find(1).send_confirmation_instructions # manually send instructions&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Recoverable===&lt;br /&gt;
Resets the user password and sends reset instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;# resets the user password and save the record, true if valid passwords are given, otherwise false&lt;br /&gt;
User.find(1).reset_password!('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# only resets the user password, without saving the record&lt;br /&gt;
user = User.find(1)&lt;br /&gt;
user.reset_password('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# creates a new token and send it with instructions about how to reset the password&lt;br /&gt;
User.find(1).send_reset_password_instructions &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Registerable===&lt;br /&gt;
Handles signing up users through a registration process, also allowing them to edit and destroy their account.&amp;lt;br&amp;gt;&lt;br /&gt;
Helps user to register themselves and also to make changes to their login credentials including deleting their account. &lt;br /&gt;
===Rememberable=== &lt;br /&gt;
Cookie handling module to manage generating and clearing of tokens for remembering the user.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;User.find(1).remember_me!  # regenerating the token&lt;br /&gt;
User.find(1).forget_me!    # clearing the token&lt;br /&gt;
&lt;br /&gt;
# generating info to put into cookies&lt;br /&gt;
User.serialize_into_cookie(user)&lt;br /&gt;
&lt;br /&gt;
# lookup the user based on the incoming cookie information&lt;br /&gt;
User.serialize_from_cookie(cookie_string)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trackable=== &lt;br /&gt;
Tracks login details for a specific user using log in count, last log in, IP address. These details help Site admin to investigate any unusual activity.&amp;lt;br&amp;gt; &lt;br /&gt;
===Timeoutable===&lt;br /&gt;
Expires sessions that have not been active in a specified period of time.&amp;lt;br&amp;gt;&lt;br /&gt;
===Validatable===&lt;br /&gt;
Provides validations of email and password to make sure that the log in details follow a given format. These can be modified to have customized validations.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;#email_required? ⇒ Boolean protected&lt;br /&gt;
#password_required? ⇒ Boolean protected&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Lockable===&lt;br /&gt;
Locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example application ==&lt;br /&gt;
Consider an application that can be accessed by an end user and a site admin. Since the admin would have extra priviledges, partitioned access would be required. This can be implemented by representing both types of users as seperate models and having their respective controller with appropiate actions.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# All administrator controllers should inherit from this controller&lt;br /&gt;
class AdminController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :authenticate_admin!&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# All end-user controllers should inherit from this controller&lt;br /&gt;
class EndUserController &amp;lt; ApplicationController&lt;br /&gt;
  before_action :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
An alternate implementaton method would be to have just one user(model) but with an &amp;lt;code&amp;gt;admin&amp;lt;/code&amp;gt; flag set to true for the admin in the model record. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class ApplicationController &amp;lt; ActionController::Base&lt;br /&gt;
  before_filer :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# All administrative controllers should inherit from this controller&lt;br /&gt;
class AdminController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :ensure_admin!&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def ensure_admin!&lt;br /&gt;
    unless current_user.admin?&lt;br /&gt;
      sign_out current_user&lt;br /&gt;
&lt;br /&gt;
      redirect_to root_path&lt;br /&gt;
&lt;br /&gt;
      return false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
With this way specific controllers can have private methods. In this case, the private method checks if the user is an admin or not. Only if the user is an admin, can they access &amp;lt;i&amp;gt;AdminController&amp;lt;/i&amp;gt; actions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Rails-Devise-Pundit&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise-pundit&amp;lt;/ref&amp;gt;===&lt;br /&gt;
Pundit extends the Devise funtionailty by providing authorization services in addition to the authentication funtionality provided by Devise.  Pundit can be used to implement user roles, and limit access to pages based on user role. &lt;br /&gt;
To list, Pundit can provide following features:&amp;lt;br&amp;gt;&lt;br /&gt;
* An admin can see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
* An admin can change a user’s role&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t change their role&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can’t see (or edit) another user’s profile&amp;lt;br&amp;gt;&lt;br /&gt;
* An ordinary user can see (and edit) their own user profile&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Other Rails Authentication==&lt;br /&gt;
OmniAuth&amp;lt;ref&amp;gt;https://github.com/intridea/omniauth&amp;lt;/ref&amp;gt;: A generalized Rack framework for multiple-provider authentication.&amp;lt;br&amp;gt;&lt;br /&gt;
Authlogic&amp;lt;ref&amp;gt;https://github.com/binarylogic/authlogic&amp;lt;/ref&amp;gt;: A clean, simple, and unobtrusive ruby authentication solution.&amp;lt;br&amp;gt;&lt;br /&gt;
Restful-authentication&amp;lt;ref&amp;gt;https://github.com/technoweenie/restful-authentication&amp;lt;/ref&amp;gt;: Generates common user authentication code for Rails/Merb, with a full test/unit and rspec suite and optional Acts as State Machine support built-in.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Devise is the most popular Rails Authentication tools. It provides a full gamut of features, and can be configured to meet most requirements. Devise often interacts with Warden which does not provide helper methods, controller classes, views, configuration options and log in failure handling. All of these things are what Devise supplies. So if you need to extend or augment Devise, you may need to implement a customized Strategy class for your own.&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94223</id>
		<title>User:Mdong3</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94223"/>
		<updated>2015-02-18T18:21:48Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Method: authenticate_user! */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;6&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Devise&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Devise &amp;lt;ref&amp;gt;https://github.com/plataformatec/devise&amp;lt;/ref&amp;gt;''' is a Rails gem used for authenticating and managing users. &lt;br /&gt;
&lt;br /&gt;
The topic write up for this page can be found [https://docs.google.com/a/ncsu.edu/document/d/1Ay5OOUkcLMC-FH61fAm3cNvB3Uyk2hJ09vHnRgqwL-k/edit here].&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
=== Security Background===&lt;br /&gt;
Web applications are relatively easy to attack, as they are simple to understand and manipulate. The Gartner Group estimates that 75% of attacks are at the web application layer, and found out &amp;quot;that out of 300 audited sites, 97% are vulnerable to attack&amp;quot;&amp;lt;ref&amp;gt;http://www.primeon.com/press/article001.php&amp;lt;/ref&amp;gt;.Security depends on the people using the framework, and sometimes on the development method. &lt;br /&gt;
There are several ways to ensure security: Encryption, LDAP, Rails Authentication, Rails Authorization, Rails Captcha, Security Tools and Spam Detection. And devise is for Rails Authentication.&lt;br /&gt;
&lt;br /&gt;
===User Authentication Process ===&lt;br /&gt;
User Authentication is responsible for the following actions:  &lt;br /&gt;
*Signup: create a new user. This user will have to register with a username, password (which will be encrypted in the database), email, and other relevant details. &lt;br /&gt;
*Login: allow a user to sign in with her/his valid username and password. The authentication process happens by matching the username and password in the database, allowing the user access to the protected actions only if the given information matches the recorded values successfully. If not, the user will be redirected to the login page again.&lt;br /&gt;
*Access Restriction: create a session to hold the authenticated user ID after login, so navigation through additional protected actions can be done easily by just checking the userID in the current session.&lt;br /&gt;
*Logout: allow the user to sign out and set the authenticated userID in session file to nil.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Started ==&lt;br /&gt;
===Devise===&lt;br /&gt;
Devise is a flexible authentication solution for Rails helping developers save  time and effort while implementing authentication mechanisms from start. User authentication is a major component of most of the web applications, primarily to determine if the user is in fact, who it is declared to be. Devise is based on Warden&amp;lt;ref&amp;gt;https://github.com/hassox/warden/wiki&amp;lt;/ref&amp;gt;. (Customized [https://github.com/rack/rack Rack] middleware that provides authentication for rack applications). Rack can be considered a middleware between web server such as Mongreal, WEBrick and frameworks such as Rails, Sinatra. &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
To list, Rails can provide the following functionality for a Rails app:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Sign up (create account)&amp;lt;br&amp;gt;&lt;br /&gt;
* Login&amp;lt;br&amp;gt;&lt;br /&gt;
* “Forgot password?” feature&amp;lt;br&amp;gt;&lt;br /&gt;
* “Remember me” (stay logged in) feature&amp;lt;br&amp;gt;&lt;br /&gt;
* Edit account (edit user profile)&amp;lt;br&amp;gt;&lt;br /&gt;
* Validate user details while regestiring&amp;lt;br&amp;gt;&lt;br /&gt;
* Confirm user registration&lt;br /&gt;
&lt;br /&gt;
Current Version: 3.4.1&amp;lt;br&amp;gt;&lt;br /&gt;
First Release: 5 years ago&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Devise===&lt;br /&gt;
Once you have created a Rails app using the &amp;quot;rails new &amp;lt;app name&amp;gt;&amp;quot; command we first need to add a line to the &amp;quot;Gemfile&amp;quot; using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;gem 'devise'&amp;quot; &amp;gt;&amp;gt; Gemfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then install the gem using:&lt;br /&gt;
&amp;lt;pre&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
The Gem will be installed for your rails application. Then run the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:install          &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create config files.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise user              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To create model(User) class and routes and to also associate the 'User' model with 'Devise'.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:migrate                        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To run the migration and create the table with certain fields appropriate for user authentication. The result should be something like: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrating ================================&lt;br /&gt;
-- create_table(:users)&lt;br /&gt;
   -&amp;gt; 0.0178s&lt;br /&gt;
-- add_index(:users, :email, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0010s&lt;br /&gt;
-- add_index(:users, :reset_password_token, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0055s&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrated (0.0255s) =======================&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:views users      &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create the directory /app/views/users with all the devise views, such as login form, registration form .&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Methods==&lt;br /&gt;
Devise provides classes, models, views, controllers, views, helpers, routes. However, these functionality are exposed in only a small number of helper methods,   not all of these components would be required to know. Some of the important Devise helper methods provided are:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Method: authenticate_user!====&lt;br /&gt;
The &amp;lt;i&amp;gt;authenticate_user!&amp;lt;/i&amp;gt; method is a class method that can be called from a controller only. The method determines if the user has access to all or a specific set of controller actions. This method is invoked via a &amp;lt;i&amp;gt;before_filter&amp;lt;/i&amp;gt;, for example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The above statements requires the user to be logged in before they can access the controller actions. To make exceptions for accessing any actions without authentications we can update the above statement as:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before_action :authenticate_user!, except: [:show]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above example, user authentication would be required to call any actions in the controller except the &amp;lt;i&amp;gt;show&amp;lt;/i&amp;gt; action. &lt;br /&gt;
So if the &amp;lt;i&amp;gt;root&amp;lt;/i&amp;gt; in the &amp;lt;code&amp;gt;config/routes.rb&amp;lt;/code&amp;gt; field is set to obtain any view belonging to the UsersController in this case, the Sign in page will be loaded before any of the actions can be accessed. &amp;lt;br&amp;gt; Once the user is authenticate, the required action is obtained.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: current_user====&lt;br /&gt;
The &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method is used to return the model class to whom the signed in user belongs. The method returns nil if a user has not yet signed in. &lt;br /&gt;
The &amp;lt;authenticate_user!&amp;gt; will make sure that the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method would never return &amp;lt;i&amp;gt;nil&amp;lt;/i&amp;gt;. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_signed_in?====&lt;br /&gt;
Checks if the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method returns a non nil value. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: sign_in(@user) and sign_out(@user)====&lt;br /&gt;
The sign_in(@user) and the sign_out(@user) are useful to login or logout a newly created user.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_session====&lt;br /&gt;
This method returns metadata regarding the logged in user.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Modules==&lt;br /&gt;
===Database Authenticatable===&lt;br /&gt;
Ensures that the user has entered the correct password and also to encrypt and stores the password in the database when the user registers for the first time. The authentication can be done both through POST requests or HTTP Basic Authentication.&amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).valid_password?('password123')         # returns true/false &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Omniauthable===&lt;br /&gt;
Adds OmniAuth (https://github.com/intridea/omniauth) support.&amp;lt;br&amp;gt;&lt;br /&gt;
===Confirmable===&lt;br /&gt;
Sends confirmation emails to Users following successful registration. This is to prevent bot registrations. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).confirm!      # returns true unless it's already confirmed&lt;br /&gt;
User.find(1).confirmed?    # true/false&lt;br /&gt;
User.find(1).send_confirmation_instructions # manually send instructions&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Recoverable===&lt;br /&gt;
Resets the user password and sends reset instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;# resets the user password and save the record, true if valid passwords are given, otherwise false&lt;br /&gt;
User.find(1).reset_password!('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# only resets the user password, without saving the record&lt;br /&gt;
user = User.find(1)&lt;br /&gt;
user.reset_password('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# creates a new token and send it with instructions about how to reset the password&lt;br /&gt;
User.find(1).send_reset_password_instructions &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Registerable===&lt;br /&gt;
Handles signing up users through a registration process, also allowing them to edit and destroy their account.&amp;lt;br&amp;gt;&lt;br /&gt;
Helps user to register themselves and also to make changes to their login credentials including deleting their account. &lt;br /&gt;
===Rememberable=== &lt;br /&gt;
Cookie handling module to manage generating and clearing of tokens for remembering the user.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;User.find(1).remember_me!  # regenerating the token&lt;br /&gt;
User.find(1).forget_me!    # clearing the token&lt;br /&gt;
&lt;br /&gt;
# generating info to put into cookies&lt;br /&gt;
User.serialize_into_cookie(user)&lt;br /&gt;
&lt;br /&gt;
# lookup the user based on the incoming cookie information&lt;br /&gt;
User.serialize_from_cookie(cookie_string)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trackable=== &lt;br /&gt;
Tracks login details for a specific user using log in count, last log in, IP address. These details help Site admin to investigate any unusual activity.&amp;lt;br&amp;gt; &lt;br /&gt;
===Timeoutable===&lt;br /&gt;
Expires sessions that have not been active in a specified period of time.&amp;lt;br&amp;gt;&lt;br /&gt;
===Validatable===&lt;br /&gt;
Provides validations of email and password to make sure that the log in details follow a given format. These can be modified to have customized validations.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;#email_required? ⇒ Boolean protected&lt;br /&gt;
#password_required? ⇒ Boolean protected&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Lockable===&lt;br /&gt;
Locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example applications ==&lt;br /&gt;
=== Devise and Rails&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
Rails 4.2 starter app with Devise for authentication.&lt;br /&gt;
====What is implemented====&lt;br /&gt;
&amp;amp;bull; Home page&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Navigation bar&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Sign up (create account)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Login&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Forgot password?” feature&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Remember me” (stay logged in) feature&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Edit account (edit user profile)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; List of users&amp;lt;br&amp;gt;&lt;br /&gt;
==== Installing ====&lt;br /&gt;
To build the example application, run:&lt;br /&gt;
&amp;lt;pre&amp;gt;rails new rails-devise -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will create a Rails app named &amp;lt;code&amp;gt;rails-devise&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
Then, select “Build a RailsApps example application”. After that, select”6) rails-devise”.&amp;lt;br&amp;gt;&lt;br /&gt;
As for additional preferences:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; If you plan to deploy to Heroku, select “Unicorn&amp;quot; as your production web server.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Use “SQLite&amp;quot; for development on Mac or Linux. If you plan to deploy to Heroku, use “PostgreSQL&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; The example application uses the default “ERB” Rails template engine.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; If you are a beginner, for test framework, select “None”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; if you choose either “Foundation&amp;quot; or “Bootstrap&amp;quot;, it will automatically install Devise views with attractive styling.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Gmail&amp;quot; is for development if you have one. if your site will be heavily used, then choose “SendGrid&amp;quot; or “Mandrill&amp;quot; for production.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; The example uses &amp;quot;Devise with default modules&amp;quot;.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Devise and Pundit and Rails&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise-pundit&amp;lt;/ref&amp;gt;===&lt;br /&gt;
It extends the rails-devise example application to add authorization with Pundit.&lt;br /&gt;
====What is implemented====&lt;br /&gt;
It adds authorization with Pundit, showing how to implement user roles, and limit access to pages based on user role.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an admin can see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an admin can change a user’s role&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t change their role&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t see (or edit) another user’s profile&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can see (and edit) their own user profile&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Installing====&lt;br /&gt;
To build the example application, run:&lt;br /&gt;
&amp;lt;pre&amp;gt;rails new rails-devise-pundit -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will create a new Rails app named &amp;lt;code&amp;gt;rails-devise-pundit&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
Then, select “Build a RailsApps example application”. After that, select ”8) rails-devise-pundit”.&amp;lt;br&amp;gt;&lt;br /&gt;
The following steps are the same as Devise and Rails.&lt;br /&gt;
&lt;br /&gt;
==Other Rails Authentication==&lt;br /&gt;
OmniAuth&amp;lt;ref&amp;gt;https://github.com/intridea/omniauth&amp;lt;/ref&amp;gt;: A generalized Rack framework for multiple-provider authentication.&amp;lt;br&amp;gt;&lt;br /&gt;
Authlogic&amp;lt;ref&amp;gt;https://github.com/binarylogic/authlogic&amp;lt;/ref&amp;gt;: A clean, simple, and unobtrusive ruby authentication solution.&amp;lt;br&amp;gt;&lt;br /&gt;
Restful-authentication&amp;lt;ref&amp;gt;https://github.com/technoweenie/restful-authentication&amp;lt;/ref&amp;gt;: Generates common user authentication code for Rails/Merb, with a full test/unit and rspec suite and optional Acts as State Machine support built-in.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Devise is the most popular Rails Authentication tools. It provides a full gamut of features, and can be configured to meet most requirements. Devise often interacts with Warden which does not provide helper methods, controller classes, views, configuration options and log in failure handling. All of these things are what Devise supplies. So if you need to extend or augment Devise, you may need to implement a customized Strategy class for your own.&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94222</id>
		<title>User:Mdong3</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94222"/>
		<updated>2015-02-18T18:13:57Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Devise */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;6&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Devise&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Devise &amp;lt;ref&amp;gt;https://github.com/plataformatec/devise&amp;lt;/ref&amp;gt;''' is a Rails gem used for authenticating and managing users. &lt;br /&gt;
&lt;br /&gt;
The topic write up for this page can be found [https://docs.google.com/a/ncsu.edu/document/d/1Ay5OOUkcLMC-FH61fAm3cNvB3Uyk2hJ09vHnRgqwL-k/edit here].&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
=== Security Background===&lt;br /&gt;
Web applications are relatively easy to attack, as they are simple to understand and manipulate. The Gartner Group estimates that 75% of attacks are at the web application layer, and found out &amp;quot;that out of 300 audited sites, 97% are vulnerable to attack&amp;quot;&amp;lt;ref&amp;gt;http://www.primeon.com/press/article001.php&amp;lt;/ref&amp;gt;.Security depends on the people using the framework, and sometimes on the development method. &lt;br /&gt;
There are several ways to ensure security: Encryption, LDAP, Rails Authentication, Rails Authorization, Rails Captcha, Security Tools and Spam Detection. And devise is for Rails Authentication.&lt;br /&gt;
&lt;br /&gt;
===User Authentication Process ===&lt;br /&gt;
User Authentication is responsible for the following actions:  &lt;br /&gt;
*Signup: create a new user. This user will have to register with a username, password (which will be encrypted in the database), email, and other relevant details. &lt;br /&gt;
*Login: allow a user to sign in with her/his valid username and password. The authentication process happens by matching the username and password in the database, allowing the user access to the protected actions only if the given information matches the recorded values successfully. If not, the user will be redirected to the login page again.&lt;br /&gt;
*Access Restriction: create a session to hold the authenticated user ID after login, so navigation through additional protected actions can be done easily by just checking the userID in the current session.&lt;br /&gt;
*Logout: allow the user to sign out and set the authenticated userID in session file to nil.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Started ==&lt;br /&gt;
===Devise===&lt;br /&gt;
Devise is a flexible authentication solution for Rails helping developers save  time and effort while implementing authentication mechanisms from start. User authentication is a major component of most of the web applications, primarily to determine if the user is in fact, who it is declared to be. Devise is based on Warden&amp;lt;ref&amp;gt;https://github.com/hassox/warden/wiki&amp;lt;/ref&amp;gt;. (Customized [https://github.com/rack/rack Rack] middleware that provides authentication for rack applications). Rack can be considered a middleware between web server such as Mongreal, WEBrick and frameworks such as Rails, Sinatra. &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
To list, Rails can provide the following functionality for a Rails app:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Sign up (create account)&amp;lt;br&amp;gt;&lt;br /&gt;
* Login&amp;lt;br&amp;gt;&lt;br /&gt;
* “Forgot password?” feature&amp;lt;br&amp;gt;&lt;br /&gt;
* “Remember me” (stay logged in) feature&amp;lt;br&amp;gt;&lt;br /&gt;
* Edit account (edit user profile)&amp;lt;br&amp;gt;&lt;br /&gt;
* Validate user details while regestiring&amp;lt;br&amp;gt;&lt;br /&gt;
* Confirm user registration&lt;br /&gt;
&lt;br /&gt;
Current Version: 3.4.1&amp;lt;br&amp;gt;&lt;br /&gt;
First Release: 5 years ago&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Devise===&lt;br /&gt;
Once you have created a Rails app using the &amp;quot;rails new &amp;lt;app name&amp;gt;&amp;quot; command we first need to add a line to the &amp;quot;Gemfile&amp;quot; using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;gem 'devise'&amp;quot; &amp;gt;&amp;gt; Gemfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then install the gem using:&lt;br /&gt;
&amp;lt;pre&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
The Gem will be installed for your rails application. Then run the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:install          &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create config files.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise user              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To create model(User) class and routes and to also associate the 'User' model with 'Devise'.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:migrate                        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To run the migration and create the table with certain fields appropriate for user authentication. The result should be something like: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrating ================================&lt;br /&gt;
-- create_table(:users)&lt;br /&gt;
   -&amp;gt; 0.0178s&lt;br /&gt;
-- add_index(:users, :email, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0010s&lt;br /&gt;
-- add_index(:users, :reset_password_token, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0055s&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrated (0.0255s) =======================&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:views users      &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create the directory /app/views/users with all the devise views, such as login form, registration form .&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Methods==&lt;br /&gt;
Devise provides classes, models, views, controllers, views, helpers, routes. However, these functionality are exposed in only a small number of helper methods,   not all of these components would be required to know. Some of the important Devise helper methods provided are:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Method: authenticate_user!====&lt;br /&gt;
The &amp;lt;i&amp;gt;authenticate_user!&amp;lt;/i&amp;gt; method is a class method that can be called from a controller only. The method determines if the user has access to all or a specific set of controller actions. This method is invoked via a &amp;lt;i&amp;gt;before_filter&amp;lt;/i&amp;gt;, for example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to make make any exceptions for accessing any actions without authentications we can update the above statement as:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before_action :authenticate_user!, except: [:show]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above example, user authentication would be required to call any actions in the controller except the &amp;lt;i&amp;gt;show&amp;lt;/i&amp;gt; action. &lt;br /&gt;
So if the &amp;lt;i&amp;gt;root&amp;lt;/i&amp;gt; in the &amp;lt;code&amp;gt;config/routes.rb&amp;lt;/code&amp;gt; field is set to obtain any view belonging to the UsersController in this case, the Sign in page will be loaded before any of the actions can be accessed. &amp;lt;br&amp;gt; Once the user is authenticate, the required action is obtained.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: current_user====&lt;br /&gt;
The &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method is used to return the model class to whom the signed in user belongs. The method returns nil if a user has not yet signed in. &lt;br /&gt;
The &amp;lt;authenticate_user!&amp;gt; will make sure that the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method would never return &amp;lt;i&amp;gt;nil&amp;lt;/i&amp;gt;. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_signed_in?====&lt;br /&gt;
Checks if the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method returns a non nil value. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: sign_in(@user) and sign_out(@user)====&lt;br /&gt;
The sign_in(@user) and the sign_out(@user) are useful to login or logout a newly created user.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_session====&lt;br /&gt;
This method returns metadata regarding the logged in user.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Modules==&lt;br /&gt;
===Database Authenticatable===&lt;br /&gt;
Ensures that the user has entered the correct password and also to encrypt and stores the password in the database when the user registers for the first time. The authentication can be done both through POST requests or HTTP Basic Authentication.&amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).valid_password?('password123')         # returns true/false &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Omniauthable===&lt;br /&gt;
Adds OmniAuth (https://github.com/intridea/omniauth) support.&amp;lt;br&amp;gt;&lt;br /&gt;
===Confirmable===&lt;br /&gt;
Sends confirmation emails to Users following successful registration. This is to prevent bot registrations. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).confirm!      # returns true unless it's already confirmed&lt;br /&gt;
User.find(1).confirmed?    # true/false&lt;br /&gt;
User.find(1).send_confirmation_instructions # manually send instructions&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Recoverable===&lt;br /&gt;
Resets the user password and sends reset instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;# resets the user password and save the record, true if valid passwords are given, otherwise false&lt;br /&gt;
User.find(1).reset_password!('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# only resets the user password, without saving the record&lt;br /&gt;
user = User.find(1)&lt;br /&gt;
user.reset_password('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# creates a new token and send it with instructions about how to reset the password&lt;br /&gt;
User.find(1).send_reset_password_instructions &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Registerable===&lt;br /&gt;
Handles signing up users through a registration process, also allowing them to edit and destroy their account.&amp;lt;br&amp;gt;&lt;br /&gt;
Helps user to register themselves and also to make changes to their login credentials including deleting their account. &lt;br /&gt;
===Rememberable=== &lt;br /&gt;
Cookie handling module to manage generating and clearing of tokens for remembering the user.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;User.find(1).remember_me!  # regenerating the token&lt;br /&gt;
User.find(1).forget_me!    # clearing the token&lt;br /&gt;
&lt;br /&gt;
# generating info to put into cookies&lt;br /&gt;
User.serialize_into_cookie(user)&lt;br /&gt;
&lt;br /&gt;
# lookup the user based on the incoming cookie information&lt;br /&gt;
User.serialize_from_cookie(cookie_string)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trackable=== &lt;br /&gt;
Tracks login details for a specific user using log in count, last log in, IP address. These details help Site admin to investigate any unusual activity.&amp;lt;br&amp;gt; &lt;br /&gt;
===Timeoutable===&lt;br /&gt;
Expires sessions that have not been active in a specified period of time.&amp;lt;br&amp;gt;&lt;br /&gt;
===Validatable===&lt;br /&gt;
Provides validations of email and password to make sure that the log in details follow a given format. These can be modified to have customized validations.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;#email_required? ⇒ Boolean protected&lt;br /&gt;
#password_required? ⇒ Boolean protected&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Lockable===&lt;br /&gt;
Locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example applications ==&lt;br /&gt;
=== Devise and Rails&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
Rails 4.2 starter app with Devise for authentication.&lt;br /&gt;
====What is implemented====&lt;br /&gt;
&amp;amp;bull; Home page&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Navigation bar&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Sign up (create account)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Login&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Forgot password?” feature&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Remember me” (stay logged in) feature&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Edit account (edit user profile)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; List of users&amp;lt;br&amp;gt;&lt;br /&gt;
==== Installing ====&lt;br /&gt;
To build the example application, run:&lt;br /&gt;
&amp;lt;pre&amp;gt;rails new rails-devise -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will create a Rails app named &amp;lt;code&amp;gt;rails-devise&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
Then, select “Build a RailsApps example application”. After that, select”6) rails-devise”.&amp;lt;br&amp;gt;&lt;br /&gt;
As for additional preferences:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; If you plan to deploy to Heroku, select “Unicorn&amp;quot; as your production web server.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Use “SQLite&amp;quot; for development on Mac or Linux. If you plan to deploy to Heroku, use “PostgreSQL&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; The example application uses the default “ERB” Rails template engine.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; If you are a beginner, for test framework, select “None”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; if you choose either “Foundation&amp;quot; or “Bootstrap&amp;quot;, it will automatically install Devise views with attractive styling.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Gmail&amp;quot; is for development if you have one. if your site will be heavily used, then choose “SendGrid&amp;quot; or “Mandrill&amp;quot; for production.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; The example uses &amp;quot;Devise with default modules&amp;quot;.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Devise and Pundit and Rails&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise-pundit&amp;lt;/ref&amp;gt;===&lt;br /&gt;
It extends the rails-devise example application to add authorization with Pundit.&lt;br /&gt;
====What is implemented====&lt;br /&gt;
It adds authorization with Pundit, showing how to implement user roles, and limit access to pages based on user role.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an admin can see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an admin can change a user’s role&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t change their role&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t see (or edit) another user’s profile&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can see (and edit) their own user profile&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Installing====&lt;br /&gt;
To build the example application, run:&lt;br /&gt;
&amp;lt;pre&amp;gt;rails new rails-devise-pundit -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will create a new Rails app named &amp;lt;code&amp;gt;rails-devise-pundit&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
Then, select “Build a RailsApps example application”. After that, select ”8) rails-devise-pundit”.&amp;lt;br&amp;gt;&lt;br /&gt;
The following steps are the same as Devise and Rails.&lt;br /&gt;
&lt;br /&gt;
==Other Rails Authentication==&lt;br /&gt;
OmniAuth&amp;lt;ref&amp;gt;https://github.com/intridea/omniauth&amp;lt;/ref&amp;gt;: A generalized Rack framework for multiple-provider authentication.&amp;lt;br&amp;gt;&lt;br /&gt;
Authlogic&amp;lt;ref&amp;gt;https://github.com/binarylogic/authlogic&amp;lt;/ref&amp;gt;: A clean, simple, and unobtrusive ruby authentication solution.&amp;lt;br&amp;gt;&lt;br /&gt;
Restful-authentication&amp;lt;ref&amp;gt;https://github.com/technoweenie/restful-authentication&amp;lt;/ref&amp;gt;: Generates common user authentication code for Rails/Merb, with a full test/unit and rspec suite and optional Acts as State Machine support built-in.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Devise is the most popular Rails Authentication tools. It provides a full gamut of features, and can be configured to meet most requirements. Devise often interacts with Warden which does not provide helper methods, controller classes, views, configuration options and log in failure handling. All of these things are what Devise supplies. So if you need to extend or augment Devise, you may need to implement a customized Strategy class for your own.&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94219</id>
		<title>User:Mdong3</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94219"/>
		<updated>2015-02-18T18:02:21Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* other Rails Authentication */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;6&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Devise&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Devise &amp;lt;ref&amp;gt;https://github.com/plataformatec/devise&amp;lt;/ref&amp;gt;''' is a Rails gem used for authenticating and managing users. &lt;br /&gt;
&lt;br /&gt;
The topic write up for this page can be found [https://docs.google.com/a/ncsu.edu/document/d/1Ay5OOUkcLMC-FH61fAm3cNvB3Uyk2hJ09vHnRgqwL-k/edit here].&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
=== Security Background===&lt;br /&gt;
Web applications are relatively easy to attack, as they are simple to understand and manipulate. The Gartner Group estimates that 75% of attacks are at the web application layer, and found out &amp;quot;that out of 300 audited sites, 97% are vulnerable to attack&amp;quot;&amp;lt;ref&amp;gt;http://www.primeon.com/press/article001.php&amp;lt;/ref&amp;gt;.Security depends on the people using the framework, and sometimes on the development method. &lt;br /&gt;
There are several ways to ensure security: Encryption, LDAP, Rails Authentication, Rails Authorization, Rails Captcha, Security Tools and Spam Detection. And devise is for Rails Authentication.&lt;br /&gt;
&lt;br /&gt;
===User Authentication Process ===&lt;br /&gt;
User Authentication is responsible for the following actions:  &lt;br /&gt;
*Signup: create a new user. This user will have to register with a username, password (which will be encrypted in the database), email, and other relevant details. &lt;br /&gt;
*Login: allow a user to sign in with her/his valid username and password. The authentication process happens by matching the username and password in the database, allowing the user access to the protected actions only if the given information matches the recorded values successfully. If not, the user will be redirected to the login page again.&lt;br /&gt;
*Access Restriction: create a session to hold the authenticated user ID after login, so navigation through additional protected actions can be done easily by just checking the userID in the current session.&lt;br /&gt;
*Logout: allow the user to sign out and set the authenticated userID in session file to nil.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Started ==&lt;br /&gt;
===Devise===&lt;br /&gt;
Devise is a flexible authentication solution for Rails helping developers save  time and effort while implementing authentication mechanisms from start. User authentication is a major component of most of the web applications, primarily to determine if the user is in fact, who it is declared to be. Devise is based on Warden&amp;lt;ref&amp;gt;https://github.com/hassox/warden/wiki&amp;lt;/ref&amp;gt;. (Customized [https://github.com/rack/rack Rack] middleware that provides authentication for rack applications). Rack can be considered a middleware between web server such as Mongreal, WEBrick and frameworks such as Rails, Sinatra. &amp;lt;br&amp;gt; &lt;br /&gt;
Current Version: 3.4.1&amp;lt;br&amp;gt;&lt;br /&gt;
First Release: 5 years ago&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Devise===&lt;br /&gt;
Once you have created a Rails app using the &amp;quot;rails new &amp;lt;app name&amp;gt;&amp;quot; command we first need to add a line to the &amp;quot;Gemfile&amp;quot; using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;gem 'devise'&amp;quot; &amp;gt;&amp;gt; Gemfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then install the gem using:&lt;br /&gt;
&amp;lt;pre&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
The Gem will be installed for your rails application. Then run the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:install          &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create config files.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise user              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To create model(User) class and routes and to also associate the 'User' model with 'Devise'.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:migrate                        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To run the migration and create the table with certain fields appropriate for user authentication. The result should be something like: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrating ================================&lt;br /&gt;
-- create_table(:users)&lt;br /&gt;
   -&amp;gt; 0.0178s&lt;br /&gt;
-- add_index(:users, :email, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0010s&lt;br /&gt;
-- add_index(:users, :reset_password_token, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0055s&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrated (0.0255s) =======================&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:views users      &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create the directory /app/views/users with all the devise views, such as login form, registration form .&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Methods==&lt;br /&gt;
Devise provides classes, models, views, controllers, views, helpers, routes. However, these functionality are exposed in only a small number of helper methods,   not all of these components would be required to know. Some of the important Devise helper methods provided are:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Method: authenticate_user!====&lt;br /&gt;
The &amp;lt;i&amp;gt;authenticate_user!&amp;lt;/i&amp;gt; method is a class method that can be called from a controller only. The method determines if the user has access to all or a specific set of controller actions. This method is invoked via a &amp;lt;i&amp;gt;before_filter&amp;lt;/i&amp;gt;, for example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to make make any exceptions for accessing any actions without authentications we can update the above statement as:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before_action :authenticate_user!, except: [:show]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above example, user authentication would be required to call any actions in the controller except the &amp;lt;i&amp;gt;show&amp;lt;/i&amp;gt; action. &lt;br /&gt;
So if the &amp;lt;i&amp;gt;root&amp;lt;/i&amp;gt; in the &amp;lt;code&amp;gt;config/routes.rb&amp;lt;/code&amp;gt; field is set to obtain any view belonging to the UsersController in this case, the Sign in page will be loaded before any of the actions can be accessed. &amp;lt;br&amp;gt; Once the user is authenticate, the required action is obtained.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: current_user====&lt;br /&gt;
The &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method is used to return the model class to whom the signed in user belongs. The method returns nil if a user has not yet signed in. &lt;br /&gt;
The &amp;lt;authenticate_user!&amp;gt; will make sure that the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method would never return &amp;lt;i&amp;gt;nil&amp;lt;/i&amp;gt;. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_signed_in?====&lt;br /&gt;
Checks if the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method returns a non nil value. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: sign_in(@user) and sign_out(@user)====&lt;br /&gt;
The sign_in(@user) and the sign_out(@user) are useful to login or logout a newly created user.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_session====&lt;br /&gt;
This method returns metadata regarding the logged in user.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Modules==&lt;br /&gt;
===Database Authenticatable===&lt;br /&gt;
Ensures that the user has entered the correct password and also to encrypt and stores the password in the database when the user registers for the first time. The authentication can be done both through POST requests or HTTP Basic Authentication.&amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).valid_password?('password123')         # returns true/false &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Omniauthable===&lt;br /&gt;
Adds OmniAuth (https://github.com/intridea/omniauth) support.&amp;lt;br&amp;gt;&lt;br /&gt;
===Confirmable===&lt;br /&gt;
Sends confirmation emails to Users following successful registration. This is to prevent bot registrations. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).confirm!      # returns true unless it's already confirmed&lt;br /&gt;
User.find(1).confirmed?    # true/false&lt;br /&gt;
User.find(1).send_confirmation_instructions # manually send instructions&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Recoverable===&lt;br /&gt;
Resets the user password and sends reset instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;# resets the user password and save the record, true if valid passwords are given, otherwise false&lt;br /&gt;
User.find(1).reset_password!('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# only resets the user password, without saving the record&lt;br /&gt;
user = User.find(1)&lt;br /&gt;
user.reset_password('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# creates a new token and send it with instructions about how to reset the password&lt;br /&gt;
User.find(1).send_reset_password_instructions &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Registerable===&lt;br /&gt;
Handles signing up users through a registration process, also allowing them to edit and destroy their account.&amp;lt;br&amp;gt;&lt;br /&gt;
Helps user to register themselves and also to make changes to their login credentials including deleting their account. &lt;br /&gt;
===Rememberable=== &lt;br /&gt;
Cookie handling module to manage generating and clearing of tokens for remembering the user.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;User.find(1).remember_me!  # regenerating the token&lt;br /&gt;
User.find(1).forget_me!    # clearing the token&lt;br /&gt;
&lt;br /&gt;
# generating info to put into cookies&lt;br /&gt;
User.serialize_into_cookie(user)&lt;br /&gt;
&lt;br /&gt;
# lookup the user based on the incoming cookie information&lt;br /&gt;
User.serialize_from_cookie(cookie_string)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trackable=== &lt;br /&gt;
Tracks login details for a specific user using log in count, last log in, IP address. These details help Site admin to investigate any unusual activity.&amp;lt;br&amp;gt; &lt;br /&gt;
===Timeoutable===&lt;br /&gt;
Expires sessions that have not been active in a specified period of time.&amp;lt;br&amp;gt;&lt;br /&gt;
===Validatable===&lt;br /&gt;
Provides validations of email and password to make sure that the log in details follow a given format. These can be modified to have customized validations.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;#email_required? ⇒ Boolean protected&lt;br /&gt;
#password_required? ⇒ Boolean protected&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Lockable===&lt;br /&gt;
Locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example applications ==&lt;br /&gt;
=== Devise and Rails&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
Rails 4.2 starter app with Devise for authentication.&lt;br /&gt;
====What is implemented====&lt;br /&gt;
&amp;amp;bull; Home page&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Navigation bar&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Sign up (create account)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Login&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Forgot password?” feature&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Remember me” (stay logged in) feature&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Edit account (edit user profile)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; List of users&amp;lt;br&amp;gt;&lt;br /&gt;
==== Installing ====&lt;br /&gt;
To build the example application, run:&lt;br /&gt;
&amp;lt;pre&amp;gt;rails new rails-devise -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will create a Rails app named &amp;lt;code&amp;gt;rails-devise&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
Then, select “Build a RailsApps example application”. After that, select”6) rails-devise”.&amp;lt;br&amp;gt;&lt;br /&gt;
As for additional preferences:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; If you plan to deploy to Heroku, select “Unicorn&amp;quot; as your production web server.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Use “SQLite&amp;quot; for development on Mac or Linux. If you plan to deploy to Heroku, use “PostgreSQL&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; The example application uses the default “ERB” Rails template engine.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; If you are a beginner, for test framework, select “None”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; if you choose either “Foundation&amp;quot; or “Bootstrap&amp;quot;, it will automatically install Devise views with attractive styling.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Gmail&amp;quot; is for development if you have one. if your site will be heavily used, then choose “SendGrid&amp;quot; or “Mandrill&amp;quot; for production.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; The example uses &amp;quot;Devise with default modules&amp;quot;.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Devise and Pundit and Rails&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise-pundit&amp;lt;/ref&amp;gt;===&lt;br /&gt;
It extends the rails-devise example application to add authorization with Pundit.&lt;br /&gt;
====What is implemented====&lt;br /&gt;
It adds authorization with Pundit, showing how to implement user roles, and limit access to pages based on user role.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an admin can see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an admin can change a user’s role&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t change their role&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t see (or edit) another user’s profile&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can see (and edit) their own user profile&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Installing====&lt;br /&gt;
To build the example application, run:&lt;br /&gt;
&amp;lt;pre&amp;gt;rails new rails-devise-pundit -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will create a new Rails app named &amp;lt;code&amp;gt;rails-devise-pundit&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
Then, select “Build a RailsApps example application”. After that, select ”8) rails-devise-pundit”.&amp;lt;br&amp;gt;&lt;br /&gt;
The following steps are the same as Devise and Rails.&lt;br /&gt;
&lt;br /&gt;
==Other Rails Authentication==&lt;br /&gt;
OmniAuth&amp;lt;ref&amp;gt;https://github.com/intridea/omniauth&amp;lt;/ref&amp;gt;: A generalized Rack framework for multiple-provider authentication.&amp;lt;br&amp;gt;&lt;br /&gt;
Authlogic&amp;lt;ref&amp;gt;https://github.com/binarylogic/authlogic&amp;lt;/ref&amp;gt;: A clean, simple, and unobtrusive ruby authentication solution.&amp;lt;br&amp;gt;&lt;br /&gt;
Restful-authentication&amp;lt;ref&amp;gt;https://github.com/technoweenie/restful-authentication&amp;lt;/ref&amp;gt;: Generates common user authentication code for Rails/Merb, with a full test/unit and rspec suite and optional Acts as State Machine support built-in.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Devise is the most popular Rails Authentication tools. It provides a full gamut of features, and can be configured to meet most requirements. Devise often interacts with Warden which does not provide helper methods, controller classes, views, configuration options and log in failure handling. All of these things are what Devise supplies. So if you need to extend or augment Devise, you may need to implement a customized Strategy class for your own.&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94218</id>
		<title>User:Mdong3</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94218"/>
		<updated>2015-02-18T18:00:59Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Method: user_session */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;6&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Devise&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Devise &amp;lt;ref&amp;gt;https://github.com/plataformatec/devise&amp;lt;/ref&amp;gt;''' is a Rails gem used for authenticating and managing users. &lt;br /&gt;
&lt;br /&gt;
The topic write up for this page can be found [https://docs.google.com/a/ncsu.edu/document/d/1Ay5OOUkcLMC-FH61fAm3cNvB3Uyk2hJ09vHnRgqwL-k/edit here].&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
=== Security Background===&lt;br /&gt;
Web applications are relatively easy to attack, as they are simple to understand and manipulate. The Gartner Group estimates that 75% of attacks are at the web application layer, and found out &amp;quot;that out of 300 audited sites, 97% are vulnerable to attack&amp;quot;&amp;lt;ref&amp;gt;http://www.primeon.com/press/article001.php&amp;lt;/ref&amp;gt;.Security depends on the people using the framework, and sometimes on the development method. &lt;br /&gt;
There are several ways to ensure security: Encryption, LDAP, Rails Authentication, Rails Authorization, Rails Captcha, Security Tools and Spam Detection. And devise is for Rails Authentication.&lt;br /&gt;
&lt;br /&gt;
===User Authentication Process ===&lt;br /&gt;
User Authentication is responsible for the following actions:  &lt;br /&gt;
*Signup: create a new user. This user will have to register with a username, password (which will be encrypted in the database), email, and other relevant details. &lt;br /&gt;
*Login: allow a user to sign in with her/his valid username and password. The authentication process happens by matching the username and password in the database, allowing the user access to the protected actions only if the given information matches the recorded values successfully. If not, the user will be redirected to the login page again.&lt;br /&gt;
*Access Restriction: create a session to hold the authenticated user ID after login, so navigation through additional protected actions can be done easily by just checking the userID in the current session.&lt;br /&gt;
*Logout: allow the user to sign out and set the authenticated userID in session file to nil.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Started ==&lt;br /&gt;
===Devise===&lt;br /&gt;
Devise is a flexible authentication solution for Rails helping developers save  time and effort while implementing authentication mechanisms from start. User authentication is a major component of most of the web applications, primarily to determine if the user is in fact, who it is declared to be. Devise is based on Warden&amp;lt;ref&amp;gt;https://github.com/hassox/warden/wiki&amp;lt;/ref&amp;gt;. (Customized [https://github.com/rack/rack Rack] middleware that provides authentication for rack applications). Rack can be considered a middleware between web server such as Mongreal, WEBrick and frameworks such as Rails, Sinatra. &amp;lt;br&amp;gt; &lt;br /&gt;
Current Version: 3.4.1&amp;lt;br&amp;gt;&lt;br /&gt;
First Release: 5 years ago&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Devise===&lt;br /&gt;
Once you have created a Rails app using the &amp;quot;rails new &amp;lt;app name&amp;gt;&amp;quot; command we first need to add a line to the &amp;quot;Gemfile&amp;quot; using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;gem 'devise'&amp;quot; &amp;gt;&amp;gt; Gemfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then install the gem using:&lt;br /&gt;
&amp;lt;pre&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
The Gem will be installed for your rails application. Then run the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:install          &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create config files.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise user              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To create model(User) class and routes and to also associate the 'User' model with 'Devise'.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:migrate                        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To run the migration and create the table with certain fields appropriate for user authentication. The result should be something like: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrating ================================&lt;br /&gt;
-- create_table(:users)&lt;br /&gt;
   -&amp;gt; 0.0178s&lt;br /&gt;
-- add_index(:users, :email, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0010s&lt;br /&gt;
-- add_index(:users, :reset_password_token, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0055s&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrated (0.0255s) =======================&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:views users      &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create the directory /app/views/users with all the devise views, such as login form, registration form .&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Methods==&lt;br /&gt;
Devise provides classes, models, views, controllers, views, helpers, routes. However, these functionality are exposed in only a small number of helper methods,   not all of these components would be required to know. Some of the important Devise helper methods provided are:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Method: authenticate_user!====&lt;br /&gt;
The &amp;lt;i&amp;gt;authenticate_user!&amp;lt;/i&amp;gt; method is a class method that can be called from a controller only. The method determines if the user has access to all or a specific set of controller actions. This method is invoked via a &amp;lt;i&amp;gt;before_filter&amp;lt;/i&amp;gt;, for example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to make make any exceptions for accessing any actions without authentications we can update the above statement as:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before_action :authenticate_user!, except: [:show]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above example, user authentication would be required to call any actions in the controller except the &amp;lt;i&amp;gt;show&amp;lt;/i&amp;gt; action. &lt;br /&gt;
So if the &amp;lt;i&amp;gt;root&amp;lt;/i&amp;gt; in the &amp;lt;code&amp;gt;config/routes.rb&amp;lt;/code&amp;gt; field is set to obtain any view belonging to the UsersController in this case, the Sign in page will be loaded before any of the actions can be accessed. &amp;lt;br&amp;gt; Once the user is authenticate, the required action is obtained.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: current_user====&lt;br /&gt;
The &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method is used to return the model class to whom the signed in user belongs. The method returns nil if a user has not yet signed in. &lt;br /&gt;
The &amp;lt;authenticate_user!&amp;gt; will make sure that the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method would never return &amp;lt;i&amp;gt;nil&amp;lt;/i&amp;gt;. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_signed_in?====&lt;br /&gt;
Checks if the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method returns a non nil value. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: sign_in(@user) and sign_out(@user)====&lt;br /&gt;
The sign_in(@user) and the sign_out(@user) are useful to login or logout a newly created user.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_session====&lt;br /&gt;
This method returns metadata regarding the logged in user.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Modules==&lt;br /&gt;
===Database Authenticatable===&lt;br /&gt;
Ensures that the user has entered the correct password and also to encrypt and stores the password in the database when the user registers for the first time. The authentication can be done both through POST requests or HTTP Basic Authentication.&amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).valid_password?('password123')         # returns true/false &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Omniauthable===&lt;br /&gt;
Adds OmniAuth (https://github.com/intridea/omniauth) support.&amp;lt;br&amp;gt;&lt;br /&gt;
===Confirmable===&lt;br /&gt;
Sends confirmation emails to Users following successful registration. This is to prevent bot registrations. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).confirm!      # returns true unless it's already confirmed&lt;br /&gt;
User.find(1).confirmed?    # true/false&lt;br /&gt;
User.find(1).send_confirmation_instructions # manually send instructions&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Recoverable===&lt;br /&gt;
Resets the user password and sends reset instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;# resets the user password and save the record, true if valid passwords are given, otherwise false&lt;br /&gt;
User.find(1).reset_password!('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# only resets the user password, without saving the record&lt;br /&gt;
user = User.find(1)&lt;br /&gt;
user.reset_password('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# creates a new token and send it with instructions about how to reset the password&lt;br /&gt;
User.find(1).send_reset_password_instructions &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Registerable===&lt;br /&gt;
Handles signing up users through a registration process, also allowing them to edit and destroy their account.&amp;lt;br&amp;gt;&lt;br /&gt;
Helps user to register themselves and also to make changes to their login credentials including deleting their account. &lt;br /&gt;
===Rememberable=== &lt;br /&gt;
Cookie handling module to manage generating and clearing of tokens for remembering the user.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;User.find(1).remember_me!  # regenerating the token&lt;br /&gt;
User.find(1).forget_me!    # clearing the token&lt;br /&gt;
&lt;br /&gt;
# generating info to put into cookies&lt;br /&gt;
User.serialize_into_cookie(user)&lt;br /&gt;
&lt;br /&gt;
# lookup the user based on the incoming cookie information&lt;br /&gt;
User.serialize_from_cookie(cookie_string)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trackable=== &lt;br /&gt;
Tracks login details for a specific user using log in count, last log in, IP address. These details help Site admin to investigate any unusual activity.&amp;lt;br&amp;gt; &lt;br /&gt;
===Timeoutable===&lt;br /&gt;
Expires sessions that have not been active in a specified period of time.&amp;lt;br&amp;gt;&lt;br /&gt;
===Validatable===&lt;br /&gt;
Provides validations of email and password to make sure that the log in details follow a given format. These can be modified to have customized validations.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;#email_required? ⇒ Boolean protected&lt;br /&gt;
#password_required? ⇒ Boolean protected&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Lockable===&lt;br /&gt;
Locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example applications ==&lt;br /&gt;
=== Devise and Rails&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
Rails 4.2 starter app with Devise for authentication.&lt;br /&gt;
====What is implemented====&lt;br /&gt;
&amp;amp;bull; Home page&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Navigation bar&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Sign up (create account)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Login&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Forgot password?” feature&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Remember me” (stay logged in) feature&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Edit account (edit user profile)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; List of users&amp;lt;br&amp;gt;&lt;br /&gt;
==== Installing ====&lt;br /&gt;
To build the example application, run:&lt;br /&gt;
&amp;lt;pre&amp;gt;rails new rails-devise -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will create a Rails app named &amp;lt;code&amp;gt;rails-devise&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
Then, select “Build a RailsApps example application”. After that, select”6) rails-devise”.&amp;lt;br&amp;gt;&lt;br /&gt;
As for additional preferences:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; If you plan to deploy to Heroku, select “Unicorn&amp;quot; as your production web server.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Use “SQLite&amp;quot; for development on Mac or Linux. If you plan to deploy to Heroku, use “PostgreSQL&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; The example application uses the default “ERB” Rails template engine.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; If you are a beginner, for test framework, select “None”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; if you choose either “Foundation&amp;quot; or “Bootstrap&amp;quot;, it will automatically install Devise views with attractive styling.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Gmail&amp;quot; is for development if you have one. if your site will be heavily used, then choose “SendGrid&amp;quot; or “Mandrill&amp;quot; for production.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; The example uses &amp;quot;Devise with default modules&amp;quot;.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Devise and Pundit and Rails&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise-pundit&amp;lt;/ref&amp;gt;===&lt;br /&gt;
It extends the rails-devise example application to add authorization with Pundit.&lt;br /&gt;
====What is implemented====&lt;br /&gt;
It adds authorization with Pundit, showing how to implement user roles, and limit access to pages based on user role.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an admin can see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an admin can change a user’s role&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t change their role&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t see (or edit) another user’s profile&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can see (and edit) their own user profile&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Installing====&lt;br /&gt;
To build the example application, run:&lt;br /&gt;
&amp;lt;pre&amp;gt;rails new rails-devise-pundit -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will create a new Rails app named &amp;lt;code&amp;gt;rails-devise-pundit&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
Then, select “Build a RailsApps example application”. After that, select ”8) rails-devise-pundit”.&amp;lt;br&amp;gt;&lt;br /&gt;
The following steps are the same as Devise and Rails.&lt;br /&gt;
&lt;br /&gt;
==other Rails Authentication==&lt;br /&gt;
OmniAuth&amp;lt;ref&amp;gt;https://github.com/intridea/omniauth&amp;lt;/ref&amp;gt;: A generalized Rack framework for multiple-provider authentication.&amp;lt;br&amp;gt;&lt;br /&gt;
Authlogic&amp;lt;ref&amp;gt;https://github.com/binarylogic/authlogic&amp;lt;/ref&amp;gt;: A clean, simple, and unobtrusive ruby authentication solution.&amp;lt;br&amp;gt;&lt;br /&gt;
Restful-authentication&amp;lt;ref&amp;gt;https://github.com/technoweenie/restful-authentication&amp;lt;/ref&amp;gt;: Generates common user authentication code for Rails/Merb, with a full test/unit and rspec suite and optional Acts as State Machine support built-in.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Devise is the most popular Rails Authentication tools. It provides a full gamut of features, and can be configured to meet most requirements. Devise often interacts with Warden which does not provide helper methods, controller classes, views, configuration options and log in failure handling. All of these things are what Devise supplies. So if you need to extend or augment Devise, you may need to implement a customized Strategy class for your own.&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94217</id>
		<title>User:Mdong3</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94217"/>
		<updated>2015-02-18T18:00:42Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Method: user_session */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;6&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Devise&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Devise &amp;lt;ref&amp;gt;https://github.com/plataformatec/devise&amp;lt;/ref&amp;gt;''' is a Rails gem used for authenticating and managing users. &lt;br /&gt;
&lt;br /&gt;
The topic write up for this page can be found [https://docs.google.com/a/ncsu.edu/document/d/1Ay5OOUkcLMC-FH61fAm3cNvB3Uyk2hJ09vHnRgqwL-k/edit here].&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
=== Security Background===&lt;br /&gt;
Web applications are relatively easy to attack, as they are simple to understand and manipulate. The Gartner Group estimates that 75% of attacks are at the web application layer, and found out &amp;quot;that out of 300 audited sites, 97% are vulnerable to attack&amp;quot;&amp;lt;ref&amp;gt;http://www.primeon.com/press/article001.php&amp;lt;/ref&amp;gt;.Security depends on the people using the framework, and sometimes on the development method. &lt;br /&gt;
There are several ways to ensure security: Encryption, LDAP, Rails Authentication, Rails Authorization, Rails Captcha, Security Tools and Spam Detection. And devise is for Rails Authentication.&lt;br /&gt;
&lt;br /&gt;
===User Authentication Process ===&lt;br /&gt;
User Authentication is responsible for the following actions:  &lt;br /&gt;
*Signup: create a new user. This user will have to register with a username, password (which will be encrypted in the database), email, and other relevant details. &lt;br /&gt;
*Login: allow a user to sign in with her/his valid username and password. The authentication process happens by matching the username and password in the database, allowing the user access to the protected actions only if the given information matches the recorded values successfully. If not, the user will be redirected to the login page again.&lt;br /&gt;
*Access Restriction: create a session to hold the authenticated user ID after login, so navigation through additional protected actions can be done easily by just checking the userID in the current session.&lt;br /&gt;
*Logout: allow the user to sign out and set the authenticated userID in session file to nil.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Started ==&lt;br /&gt;
===Devise===&lt;br /&gt;
Devise is a flexible authentication solution for Rails helping developers save  time and effort while implementing authentication mechanisms from start. User authentication is a major component of most of the web applications, primarily to determine if the user is in fact, who it is declared to be. Devise is based on Warden&amp;lt;ref&amp;gt;https://github.com/hassox/warden/wiki&amp;lt;/ref&amp;gt;. (Customized [https://github.com/rack/rack Rack] middleware that provides authentication for rack applications). Rack can be considered a middleware between web server such as Mongreal, WEBrick and frameworks such as Rails, Sinatra. &amp;lt;br&amp;gt; &lt;br /&gt;
Current Version: 3.4.1&amp;lt;br&amp;gt;&lt;br /&gt;
First Release: 5 years ago&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Devise===&lt;br /&gt;
Once you have created a Rails app using the &amp;quot;rails new &amp;lt;app name&amp;gt;&amp;quot; command we first need to add a line to the &amp;quot;Gemfile&amp;quot; using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;gem 'devise'&amp;quot; &amp;gt;&amp;gt; Gemfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then install the gem using:&lt;br /&gt;
&amp;lt;pre&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
The Gem will be installed for your rails application. Then run the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:install          &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create config files.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise user              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To create model(User) class and routes and to also associate the 'User' model with 'Devise'.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:migrate                        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To run the migration and create the table with certain fields appropriate for user authentication. The result should be something like: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrating ================================&lt;br /&gt;
-- create_table(:users)&lt;br /&gt;
   -&amp;gt; 0.0178s&lt;br /&gt;
-- add_index(:users, :email, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0010s&lt;br /&gt;
-- add_index(:users, :reset_password_token, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0055s&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrated (0.0255s) =======================&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:views users      &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create the directory /app/views/users with all the devise views, such as login form, registration form .&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Methods==&lt;br /&gt;
Devise provides classes, models, views, controllers, views, helpers, routes. However, these functionality are exposed in only a small number of helper methods,   not all of these components would be required to know. Some of the important Devise helper methods provided are:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Method: authenticate_user!====&lt;br /&gt;
The &amp;lt;i&amp;gt;authenticate_user!&amp;lt;/i&amp;gt; method is a class method that can be called from a controller only. The method determines if the user has access to all or a specific set of controller actions. This method is invoked via a &amp;lt;i&amp;gt;before_filter&amp;lt;/i&amp;gt;, for example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to make make any exceptions for accessing any actions without authentications we can update the above statement as:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before_action :authenticate_user!, except: [:show]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above example, user authentication would be required to call any actions in the controller except the &amp;lt;i&amp;gt;show&amp;lt;/i&amp;gt; action. &lt;br /&gt;
So if the &amp;lt;i&amp;gt;root&amp;lt;/i&amp;gt; in the &amp;lt;code&amp;gt;config/routes.rb&amp;lt;/code&amp;gt; field is set to obtain any view belonging to the UsersController in this case, the Sign in page will be loaded before any of the actions can be accessed. &amp;lt;br&amp;gt; Once the user is authenticate, the required action is obtained.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: current_user====&lt;br /&gt;
The &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method is used to return the model class to whom the signed in user belongs. The method returns nil if a user has not yet signed in. &lt;br /&gt;
The &amp;lt;authenticate_user!&amp;gt; will make sure that the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method would never return &amp;lt;i&amp;gt;nil&amp;lt;/i&amp;gt;. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_signed_in?====&lt;br /&gt;
Checks if the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method returns a non nil value. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: sign_in(@user) and sign_out(@user)====&lt;br /&gt;
The sign_in(@user) and the sign_out(@user) are useful to login or logout a newly created user.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_session====&lt;br /&gt;
This method returns metadata regarding the logged in user.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Modules==&lt;br /&gt;
===Database Authenticatable===&lt;br /&gt;
Ensures that the user has entered the correct password and also to encrypt and stores the password in the database when the user registers for the first time. The authentication can be done both through POST requests or HTTP Basic Authentication.&amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).valid_password?('password123')         # returns true/false &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Omniauthable===&lt;br /&gt;
Adds OmniAuth (https://github.com/intridea/omniauth) support.&amp;lt;br&amp;gt;&lt;br /&gt;
===Confirmable===&lt;br /&gt;
Sends confirmation emails to Users following successful registration. This is to prevent bot registrations. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).confirm!      # returns true unless it's already confirmed&lt;br /&gt;
User.find(1).confirmed?    # true/false&lt;br /&gt;
User.find(1).send_confirmation_instructions # manually send instructions&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Recoverable===&lt;br /&gt;
Resets the user password and sends reset instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;# resets the user password and save the record, true if valid passwords are given, otherwise false&lt;br /&gt;
User.find(1).reset_password!('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# only resets the user password, without saving the record&lt;br /&gt;
user = User.find(1)&lt;br /&gt;
user.reset_password('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# creates a new token and send it with instructions about how to reset the password&lt;br /&gt;
User.find(1).send_reset_password_instructions &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Registerable===&lt;br /&gt;
Handles signing up users through a registration process, also allowing them to edit and destroy their account.&amp;lt;br&amp;gt;&lt;br /&gt;
Helps user to register themselves and also to make changes to their login credentials including deleting their account. &lt;br /&gt;
===Rememberable=== &lt;br /&gt;
Cookie handling module to manage generating and clearing of tokens for remembering the user.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;User.find(1).remember_me!  # regenerating the token&lt;br /&gt;
User.find(1).forget_me!    # clearing the token&lt;br /&gt;
&lt;br /&gt;
# generating info to put into cookies&lt;br /&gt;
User.serialize_into_cookie(user)&lt;br /&gt;
&lt;br /&gt;
# lookup the user based on the incoming cookie information&lt;br /&gt;
User.serialize_from_cookie(cookie_string)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trackable=== &lt;br /&gt;
Tracks login details for a specific user using log in count, last log in, IP address. These details help Site admin to investigate any unusual activity.&amp;lt;br&amp;gt; &lt;br /&gt;
===Timeoutable===&lt;br /&gt;
Expires sessions that have not been active in a specified period of time.&amp;lt;br&amp;gt;&lt;br /&gt;
===Validatable===&lt;br /&gt;
Provides validations of email and password to make sure that the log in details follow a given format. These can be modified to have customized validations.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;#email_required? ⇒ Boolean protected&lt;br /&gt;
#password_required? ⇒ Boolean protected&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Lockable===&lt;br /&gt;
Locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example applications ==&lt;br /&gt;
=== Devise and Rails&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
Rails 4.2 starter app with Devise for authentication.&lt;br /&gt;
====What is implemented====&lt;br /&gt;
&amp;amp;bull; Home page&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Navigation bar&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Sign up (create account)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Login&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Forgot password?” feature&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Remember me” (stay logged in) feature&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Edit account (edit user profile)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; List of users&amp;lt;br&amp;gt;&lt;br /&gt;
==== Installing ====&lt;br /&gt;
To build the example application, run:&lt;br /&gt;
&amp;lt;pre&amp;gt;rails new rails-devise -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will create a Rails app named &amp;lt;code&amp;gt;rails-devise&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
Then, select “Build a RailsApps example application”. After that, select”6) rails-devise”.&amp;lt;br&amp;gt;&lt;br /&gt;
As for additional preferences:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; If you plan to deploy to Heroku, select “Unicorn&amp;quot; as your production web server.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Use “SQLite&amp;quot; for development on Mac or Linux. If you plan to deploy to Heroku, use “PostgreSQL&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; The example application uses the default “ERB” Rails template engine.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; If you are a beginner, for test framework, select “None”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; if you choose either “Foundation&amp;quot; or “Bootstrap&amp;quot;, it will automatically install Devise views with attractive styling.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Gmail&amp;quot; is for development if you have one. if your site will be heavily used, then choose “SendGrid&amp;quot; or “Mandrill&amp;quot; for production.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; The example uses &amp;quot;Devise with default modules&amp;quot;.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Devise and Pundit and Rails&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise-pundit&amp;lt;/ref&amp;gt;===&lt;br /&gt;
It extends the rails-devise example application to add authorization with Pundit.&lt;br /&gt;
====What is implemented====&lt;br /&gt;
It adds authorization with Pundit, showing how to implement user roles, and limit access to pages based on user role.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an admin can see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an admin can change a user’s role&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t change their role&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t see (or edit) another user’s profile&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can see (and edit) their own user profile&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Installing====&lt;br /&gt;
To build the example application, run:&lt;br /&gt;
&amp;lt;pre&amp;gt;rails new rails-devise-pundit -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will create a new Rails app named &amp;lt;code&amp;gt;rails-devise-pundit&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
Then, select “Build a RailsApps example application”. After that, select ”8) rails-devise-pundit”.&amp;lt;br&amp;gt;&lt;br /&gt;
The following steps are the same as Devise and Rails.&lt;br /&gt;
&lt;br /&gt;
==other Rails Authentication==&lt;br /&gt;
OmniAuth&amp;lt;ref&amp;gt;https://github.com/intridea/omniauth&amp;lt;/ref&amp;gt;: A generalized Rack framework for multiple-provider authentication.&amp;lt;br&amp;gt;&lt;br /&gt;
Authlogic&amp;lt;ref&amp;gt;https://github.com/binarylogic/authlogic&amp;lt;/ref&amp;gt;: A clean, simple, and unobtrusive ruby authentication solution.&amp;lt;br&amp;gt;&lt;br /&gt;
Restful-authentication&amp;lt;ref&amp;gt;https://github.com/technoweenie/restful-authentication&amp;lt;/ref&amp;gt;: Generates common user authentication code for Rails/Merb, with a full test/unit and rspec suite and optional Acts as State Machine support built-in.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Devise is the most popular Rails Authentication tools. It provides a full gamut of features, and can be configured to meet most requirements. Devise often interacts with Warden which does not provide helper methods, controller classes, views, configuration options and log in failure handling. All of these things are what Devise supplies. So if you need to extend or augment Devise, you may need to implement a customized Strategy class for your own.&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94215</id>
		<title>User:Mdong3</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94215"/>
		<updated>2015-02-18T17:57:31Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Devise Methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;6&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Devise&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Devise &amp;lt;ref&amp;gt;https://github.com/plataformatec/devise&amp;lt;/ref&amp;gt;''' is a Rails gem used for authenticating and managing users. &lt;br /&gt;
&lt;br /&gt;
The topic write up for this page can be found [https://docs.google.com/a/ncsu.edu/document/d/1Ay5OOUkcLMC-FH61fAm3cNvB3Uyk2hJ09vHnRgqwL-k/edit here].&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
=== Security Background===&lt;br /&gt;
Web applications are relatively easy to attack, as they are simple to understand and manipulate. The Gartner Group estimates that 75% of attacks are at the web application layer, and found out &amp;quot;that out of 300 audited sites, 97% are vulnerable to attack&amp;quot;&amp;lt;ref&amp;gt;http://www.primeon.com/press/article001.php&amp;lt;/ref&amp;gt;.Security depends on the people using the framework, and sometimes on the development method. &lt;br /&gt;
There are several ways to ensure security: Encryption, LDAP, Rails Authentication, Rails Authorization, Rails Captcha, Security Tools and Spam Detection. And devise is for Rails Authentication.&lt;br /&gt;
&lt;br /&gt;
===User Authentication Process ===&lt;br /&gt;
User Authentication is responsible for the following actions:  &lt;br /&gt;
*Signup: create a new user. This user will have to register with a username, password (which will be encrypted in the database), email, and other relevant details. &lt;br /&gt;
*Login: allow a user to sign in with her/his valid username and password. The authentication process happens by matching the username and password in the database, allowing the user access to the protected actions only if the given information matches the recorded values successfully. If not, the user will be redirected to the login page again.&lt;br /&gt;
*Access Restriction: create a session to hold the authenticated user ID after login, so navigation through additional protected actions can be done easily by just checking the userID in the current session.&lt;br /&gt;
*Logout: allow the user to sign out and set the authenticated userID in session file to nil.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Started ==&lt;br /&gt;
===Devise===&lt;br /&gt;
Devise is a flexible authentication solution for Rails helping developers save  time and effort while implementing authentication mechanisms from start. User authentication is a major component of most of the web applications, primarily to determine if the user is in fact, who it is declared to be. Devise is based on Warden&amp;lt;ref&amp;gt;https://github.com/hassox/warden/wiki&amp;lt;/ref&amp;gt;. (Customized [https://github.com/rack/rack Rack] middleware that provides authentication for rack applications). Rack can be considered a middleware between web server such as Mongreal, WEBrick and frameworks such as Rails, Sinatra. &amp;lt;br&amp;gt; &lt;br /&gt;
Current Version: 3.4.1&amp;lt;br&amp;gt;&lt;br /&gt;
First Release: 5 years ago&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Devise===&lt;br /&gt;
Once you have created a Rails app using the &amp;quot;rails new &amp;lt;app name&amp;gt;&amp;quot; command we first need to add a line to the &amp;quot;Gemfile&amp;quot; using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;gem 'devise'&amp;quot; &amp;gt;&amp;gt; Gemfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then install the gem using:&lt;br /&gt;
&amp;lt;pre&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
The Gem will be installed for your rails application. Then run the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:install          &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create config files.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise user              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To create model(User) class and routes and to also associate the 'User' model with 'Devise'.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:migrate                        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To run the migration and create the table with certain fields appropriate for user authentication. The result should be something like: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrating ================================&lt;br /&gt;
-- create_table(:users)&lt;br /&gt;
   -&amp;gt; 0.0178s&lt;br /&gt;
-- add_index(:users, :email, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0010s&lt;br /&gt;
-- add_index(:users, :reset_password_token, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0055s&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrated (0.0255s) =======================&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:views users      &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create the directory /app/views/users with all the devise views, such as login form, registration form .&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Methods==&lt;br /&gt;
Devise provides classes, models, views, controllers, views, helpers, routes. However, these functionality are exposed in only a small number of helper methods,   not all of these components would be required to know. Some of the important Devise helper methods provided are:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Method: authenticate_user!====&lt;br /&gt;
The &amp;lt;i&amp;gt;authenticate_user!&amp;lt;/i&amp;gt; method is a class method that can be called from a controller only. The method determines if the user has access to all or a specific set of controller actions. This method is invoked via a &amp;lt;i&amp;gt;before_filter&amp;lt;/i&amp;gt;, for example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to make make any exceptions for accessing any actions without authentications we can update the above statement as:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before_action :authenticate_user!, except: [:show]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above example, user authentication would be required to call any actions in the controller except the &amp;lt;i&amp;gt;show&amp;lt;/i&amp;gt; action. &lt;br /&gt;
So if the &amp;lt;i&amp;gt;root&amp;lt;/i&amp;gt; in the &amp;lt;code&amp;gt;config/routes.rb&amp;lt;/code&amp;gt; field is set to obtain any view belonging to the UsersController in this case, the Sign in page will be loaded before any of the actions can be accessed. &amp;lt;br&amp;gt; Once the user is authenticate, the required action is obtained.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: current_user====&lt;br /&gt;
The &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method is used to return the model class to whom the signed in user belongs. The method returns nil if a user has not yet signed in. &lt;br /&gt;
The &amp;lt;authenticate_user!&amp;gt; will make sure that the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method would never return &amp;lt;i&amp;gt;nil&amp;lt;/i&amp;gt;. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_signed_in?====&lt;br /&gt;
Checks if the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method returns a non nil value. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: sign_in(@user) and sign_out(@user)====&lt;br /&gt;
The sign_in(@user) and the sign_out(@user) are useful to login or logout a newly created user.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_session====&lt;br /&gt;
This method returns metadata regarding the logged in user.&lt;br /&gt;
&lt;br /&gt;
==Devise Modules==&lt;br /&gt;
===Database Authenticatable===&lt;br /&gt;
Ensures that the user has entered the correct password and also to encrypt and stores the password in the database when the user registers for the first time. The authentication can be done both through POST requests or HTTP Basic Authentication.&amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).valid_password?('password123')         # returns true/false &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Omniauthable===&lt;br /&gt;
Adds OmniAuth (https://github.com/intridea/omniauth) support.&amp;lt;br&amp;gt;&lt;br /&gt;
===Confirmable===&lt;br /&gt;
Sends confirmation emails to Users following successful registration. This is to prevent bot registrations. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).confirm!      # returns true unless it's already confirmed&lt;br /&gt;
User.find(1).confirmed?    # true/false&lt;br /&gt;
User.find(1).send_confirmation_instructions # manually send instructions&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Recoverable===&lt;br /&gt;
Resets the user password and sends reset instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;# resets the user password and save the record, true if valid passwords are given, otherwise false&lt;br /&gt;
User.find(1).reset_password!('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# only resets the user password, without saving the record&lt;br /&gt;
user = User.find(1)&lt;br /&gt;
user.reset_password('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# creates a new token and send it with instructions about how to reset the password&lt;br /&gt;
User.find(1).send_reset_password_instructions &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Registerable===&lt;br /&gt;
Handles signing up users through a registration process, also allowing them to edit and destroy their account.&amp;lt;br&amp;gt;&lt;br /&gt;
Helps user to register themselves and also to make changes to their login credentials including deleting their account. &lt;br /&gt;
===Rememberable=== &lt;br /&gt;
Cookie handling module to manage generating and clearing of tokens for remembering the user.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;User.find(1).remember_me!  # regenerating the token&lt;br /&gt;
User.find(1).forget_me!    # clearing the token&lt;br /&gt;
&lt;br /&gt;
# generating info to put into cookies&lt;br /&gt;
User.serialize_into_cookie(user)&lt;br /&gt;
&lt;br /&gt;
# lookup the user based on the incoming cookie information&lt;br /&gt;
User.serialize_from_cookie(cookie_string)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trackable=== &lt;br /&gt;
Tracks login details for a specific user using log in count, last log in, IP address. These details help Site admin to investigate any unusual activity.&amp;lt;br&amp;gt; &lt;br /&gt;
===Timeoutable===&lt;br /&gt;
Expires sessions that have not been active in a specified period of time.&amp;lt;br&amp;gt;&lt;br /&gt;
===Validatable===&lt;br /&gt;
Provides validations of email and password to make sure that the log in details follow a given format. These can be modified to have customized validations.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;#email_required? ⇒ Boolean protected&lt;br /&gt;
#password_required? ⇒ Boolean protected&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Lockable===&lt;br /&gt;
Locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example applications ==&lt;br /&gt;
=== Devise and Rails&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
Rails 4.2 starter app with Devise for authentication.&lt;br /&gt;
====What is implemented====&lt;br /&gt;
&amp;amp;bull; Home page&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Navigation bar&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Sign up (create account)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Login&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Forgot password?” feature&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Remember me” (stay logged in) feature&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Edit account (edit user profile)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; List of users&amp;lt;br&amp;gt;&lt;br /&gt;
==== Installing ====&lt;br /&gt;
To build the example application, run:&lt;br /&gt;
&amp;lt;pre&amp;gt;rails new rails-devise -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will create a Rails app named &amp;lt;code&amp;gt;rails-devise&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
Then, select “Build a RailsApps example application”. After that, select”6) rails-devise”.&amp;lt;br&amp;gt;&lt;br /&gt;
As for additional preferences:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; If you plan to deploy to Heroku, select “Unicorn&amp;quot; as your production web server.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Use “SQLite&amp;quot; for development on Mac or Linux. If you plan to deploy to Heroku, use “PostgreSQL&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; The example application uses the default “ERB” Rails template engine.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; If you are a beginner, for test framework, select “None”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; if you choose either “Foundation&amp;quot; or “Bootstrap&amp;quot;, it will automatically install Devise views with attractive styling.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Gmail&amp;quot; is for development if you have one. if your site will be heavily used, then choose “SendGrid&amp;quot; or “Mandrill&amp;quot; for production.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; The example uses &amp;quot;Devise with default modules&amp;quot;.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Devise and Pundit and Rails&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise-pundit&amp;lt;/ref&amp;gt;===&lt;br /&gt;
It extends the rails-devise example application to add authorization with Pundit.&lt;br /&gt;
====What is implemented====&lt;br /&gt;
It adds authorization with Pundit, showing how to implement user roles, and limit access to pages based on user role.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an admin can see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an admin can change a user’s role&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t change their role&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t see (or edit) another user’s profile&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can see (and edit) their own user profile&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Installing====&lt;br /&gt;
To build the example application, run:&lt;br /&gt;
&amp;lt;pre&amp;gt;rails new rails-devise-pundit -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will create a new Rails app named &amp;lt;code&amp;gt;rails-devise-pundit&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
Then, select “Build a RailsApps example application”. After that, select ”8) rails-devise-pundit”.&amp;lt;br&amp;gt;&lt;br /&gt;
The following steps are the same as Devise and Rails.&lt;br /&gt;
&lt;br /&gt;
==other Rails Authentication==&lt;br /&gt;
OmniAuth&amp;lt;ref&amp;gt;https://github.com/intridea/omniauth&amp;lt;/ref&amp;gt;: A generalized Rack framework for multiple-provider authentication.&amp;lt;br&amp;gt;&lt;br /&gt;
Authlogic&amp;lt;ref&amp;gt;https://github.com/binarylogic/authlogic&amp;lt;/ref&amp;gt;: A clean, simple, and unobtrusive ruby authentication solution.&amp;lt;br&amp;gt;&lt;br /&gt;
Restful-authentication&amp;lt;ref&amp;gt;https://github.com/technoweenie/restful-authentication&amp;lt;/ref&amp;gt;: Generates common user authentication code for Rails/Merb, with a full test/unit and rspec suite and optional Acts as State Machine support built-in.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Devise is the most popular Rails Authentication tools. It provides a full gamut of features, and can be configured to meet most requirements. Devise often interacts with Warden which does not provide helper methods, controller classes, views, configuration options and log in failure handling. All of these things are what Devise supplies. So if you need to extend or augment Devise, you may need to implement a customized Strategy class for your own.&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94214</id>
		<title>User:Mdong3</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94214"/>
		<updated>2015-02-18T17:54:30Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Setup Devise */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;6&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Devise&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Devise &amp;lt;ref&amp;gt;https://github.com/plataformatec/devise&amp;lt;/ref&amp;gt;''' is a Rails gem used for authenticating and managing users. &lt;br /&gt;
&lt;br /&gt;
The topic write up for this page can be found [https://docs.google.com/a/ncsu.edu/document/d/1Ay5OOUkcLMC-FH61fAm3cNvB3Uyk2hJ09vHnRgqwL-k/edit here].&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
=== Security Background===&lt;br /&gt;
Web applications are relatively easy to attack, as they are simple to understand and manipulate. The Gartner Group estimates that 75% of attacks are at the web application layer, and found out &amp;quot;that out of 300 audited sites, 97% are vulnerable to attack&amp;quot;&amp;lt;ref&amp;gt;http://www.primeon.com/press/article001.php&amp;lt;/ref&amp;gt;.Security depends on the people using the framework, and sometimes on the development method. &lt;br /&gt;
There are several ways to ensure security: Encryption, LDAP, Rails Authentication, Rails Authorization, Rails Captcha, Security Tools and Spam Detection. And devise is for Rails Authentication.&lt;br /&gt;
&lt;br /&gt;
===User Authentication Process ===&lt;br /&gt;
User Authentication is responsible for the following actions:  &lt;br /&gt;
*Signup: create a new user. This user will have to register with a username, password (which will be encrypted in the database), email, and other relevant details. &lt;br /&gt;
*Login: allow a user to sign in with her/his valid username and password. The authentication process happens by matching the username and password in the database, allowing the user access to the protected actions only if the given information matches the recorded values successfully. If not, the user will be redirected to the login page again.&lt;br /&gt;
*Access Restriction: create a session to hold the authenticated user ID after login, so navigation through additional protected actions can be done easily by just checking the userID in the current session.&lt;br /&gt;
*Logout: allow the user to sign out and set the authenticated userID in session file to nil.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Started ==&lt;br /&gt;
===Devise===&lt;br /&gt;
Devise is a flexible authentication solution for Rails helping developers save  time and effort while implementing authentication mechanisms from start. User authentication is a major component of most of the web applications, primarily to determine if the user is in fact, who it is declared to be. Devise is based on Warden&amp;lt;ref&amp;gt;https://github.com/hassox/warden/wiki&amp;lt;/ref&amp;gt;. (Customized [https://github.com/rack/rack Rack] middleware that provides authentication for rack applications). Rack can be considered a middleware between web server such as Mongreal, WEBrick and frameworks such as Rails, Sinatra. &amp;lt;br&amp;gt; &lt;br /&gt;
Current Version: 3.4.1&amp;lt;br&amp;gt;&lt;br /&gt;
First Release: 5 years ago&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Devise===&lt;br /&gt;
Once you have created a Rails app using the &amp;quot;rails new &amp;lt;app name&amp;gt;&amp;quot; command we first need to add a line to the &amp;quot;Gemfile&amp;quot; using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;gem 'devise'&amp;quot; &amp;gt;&amp;gt; Gemfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then install the gem using:&lt;br /&gt;
&amp;lt;pre&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
The Gem will be installed for your rails application. Then run the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:install          &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create config files.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise user              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To create model(User) class and routes and to also associate the 'User' model with 'Devise'.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:migrate                        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To run the migration and create the table with certain fields appropriate for user authentication. The result should be something like: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrating ================================&lt;br /&gt;
-- create_table(:users)&lt;br /&gt;
   -&amp;gt; 0.0178s&lt;br /&gt;
-- add_index(:users, :email, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0010s&lt;br /&gt;
-- add_index(:users, :reset_password_token, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0055s&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrated (0.0255s) =======================&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:views users      &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create the directory /app/views/users with all the devise views, such as login form, registration form .&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Methods==&lt;br /&gt;
Devise provides classes, models, views, controllers, views, helpers, routes. However, these functionality are exposed in only a small number of helper methods,   not all of these components would be required to know. Some of the important Devise helper methods provided are:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Method: authenticate_user!====&lt;br /&gt;
The &amp;lt;i&amp;gt;authenticate_user!&amp;lt;/i&amp;gt; method is a class method that can be called from a controller only. The method determines if the user has access to all or a specific set of controller actions. This method is invoked via a &amp;lt;i&amp;gt;before_filter&amp;lt;/i&amp;gt;, for example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;to make make any exceptions for accessing any actions without authentications we can update the above statement as:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before_action :authenticate_user!, except: [:show]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above example, user authentication would be required to call any actions in the controller except the &amp;lt;i&amp;gt;show&amp;lt;/i&amp;gt; action. &lt;br /&gt;
So if the &amp;lt;i&amp;gt;root&amp;lt;/i&amp;gt; in the &amp;lt;code&amp;gt;config/routes.rb&amp;lt;/code&amp;gt; field is set to obtain any view belonging to the UsersController in this case, the Sign in page will be loaded before any of the actions can be accessed. &amp;lt;br&amp;gt; Once the user is authenticate, the required action is obtained.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: current_user====&lt;br /&gt;
The &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method is used to return the model class to whom the signed in user belongs. The method returns nil if a user has not yet signed in. &lt;br /&gt;
The &amp;lt;authenticate_user!&amp;gt; will make sure that the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method would never return &amp;lt;i&amp;gt;nil&amp;lt;/i&amp;gt;. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_signed_in?====&lt;br /&gt;
Checks if the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method returns a non nil value. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: sign_in(@user) and sign_out(@user)====&lt;br /&gt;
The sign_in(@user) and the sign_out(@user) are useful to login or logout a newly created user.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_session====&lt;br /&gt;
This method returns metadata regarding the logged in user.&lt;br /&gt;
&lt;br /&gt;
==Devise Modules==&lt;br /&gt;
===Database Authenticatable===&lt;br /&gt;
Ensures that the user has entered the correct password and also to encrypt and stores the password in the database when the user registers for the first time. The authentication can be done both through POST requests or HTTP Basic Authentication.&amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).valid_password?('password123')         # returns true/false &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Omniauthable===&lt;br /&gt;
Adds OmniAuth (https://github.com/intridea/omniauth) support.&amp;lt;br&amp;gt;&lt;br /&gt;
===Confirmable===&lt;br /&gt;
Sends confirmation emails to Users following successful registration. This is to prevent bot registrations. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).confirm!      # returns true unless it's already confirmed&lt;br /&gt;
User.find(1).confirmed?    # true/false&lt;br /&gt;
User.find(1).send_confirmation_instructions # manually send instructions&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Recoverable===&lt;br /&gt;
Resets the user password and sends reset instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;# resets the user password and save the record, true if valid passwords are given, otherwise false&lt;br /&gt;
User.find(1).reset_password!('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# only resets the user password, without saving the record&lt;br /&gt;
user = User.find(1)&lt;br /&gt;
user.reset_password('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# creates a new token and send it with instructions about how to reset the password&lt;br /&gt;
User.find(1).send_reset_password_instructions &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Registerable===&lt;br /&gt;
Handles signing up users through a registration process, also allowing them to edit and destroy their account.&amp;lt;br&amp;gt;&lt;br /&gt;
Helps user to register themselves and also to make changes to their login credentials including deleting their account. &lt;br /&gt;
===Rememberable=== &lt;br /&gt;
Cookie handling module to manage generating and clearing of tokens for remembering the user.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;User.find(1).remember_me!  # regenerating the token&lt;br /&gt;
User.find(1).forget_me!    # clearing the token&lt;br /&gt;
&lt;br /&gt;
# generating info to put into cookies&lt;br /&gt;
User.serialize_into_cookie(user)&lt;br /&gt;
&lt;br /&gt;
# lookup the user based on the incoming cookie information&lt;br /&gt;
User.serialize_from_cookie(cookie_string)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trackable=== &lt;br /&gt;
Tracks login details for a specific user using log in count, last log in, IP address. These details help Site admin to investigate any unusual activity.&amp;lt;br&amp;gt; &lt;br /&gt;
===Timeoutable===&lt;br /&gt;
Expires sessions that have not been active in a specified period of time.&amp;lt;br&amp;gt;&lt;br /&gt;
===Validatable===&lt;br /&gt;
Provides validations of email and password to make sure that the log in details follow a given format. These can be modified to have customized validations.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;#email_required? ⇒ Boolean protected&lt;br /&gt;
#password_required? ⇒ Boolean protected&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Lockable===&lt;br /&gt;
Locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example applications ==&lt;br /&gt;
=== Devise and Rails&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
Rails 4.2 starter app with Devise for authentication.&lt;br /&gt;
====What is implemented====&lt;br /&gt;
&amp;amp;bull; Home page&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Navigation bar&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Sign up (create account)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Login&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Forgot password?” feature&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Remember me” (stay logged in) feature&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Edit account (edit user profile)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; List of users&amp;lt;br&amp;gt;&lt;br /&gt;
==== Installing ====&lt;br /&gt;
To build the example application, run:&lt;br /&gt;
&amp;lt;pre&amp;gt;rails new rails-devise -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will create a Rails app named &amp;lt;code&amp;gt;rails-devise&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
Then, select “Build a RailsApps example application”. After that, select”6) rails-devise”.&amp;lt;br&amp;gt;&lt;br /&gt;
As for additional preferences:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; If you plan to deploy to Heroku, select “Unicorn&amp;quot; as your production web server.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Use “SQLite&amp;quot; for development on Mac or Linux. If you plan to deploy to Heroku, use “PostgreSQL&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; The example application uses the default “ERB” Rails template engine.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; If you are a beginner, for test framework, select “None”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; if you choose either “Foundation&amp;quot; or “Bootstrap&amp;quot;, it will automatically install Devise views with attractive styling.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Gmail&amp;quot; is for development if you have one. if your site will be heavily used, then choose “SendGrid&amp;quot; or “Mandrill&amp;quot; for production.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; The example uses &amp;quot;Devise with default modules&amp;quot;.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Devise and Pundit and Rails&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise-pundit&amp;lt;/ref&amp;gt;===&lt;br /&gt;
It extends the rails-devise example application to add authorization with Pundit.&lt;br /&gt;
====What is implemented====&lt;br /&gt;
It adds authorization with Pundit, showing how to implement user roles, and limit access to pages based on user role.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an admin can see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an admin can change a user’s role&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t change their role&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t see (or edit) another user’s profile&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can see (and edit) their own user profile&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Installing====&lt;br /&gt;
To build the example application, run:&lt;br /&gt;
&amp;lt;pre&amp;gt;rails new rails-devise-pundit -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will create a new Rails app named &amp;lt;code&amp;gt;rails-devise-pundit&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
Then, select “Build a RailsApps example application”. After that, select ”8) rails-devise-pundit”.&amp;lt;br&amp;gt;&lt;br /&gt;
The following steps are the same as Devise and Rails.&lt;br /&gt;
&lt;br /&gt;
==other Rails Authentication==&lt;br /&gt;
OmniAuth&amp;lt;ref&amp;gt;https://github.com/intridea/omniauth&amp;lt;/ref&amp;gt;: A generalized Rack framework for multiple-provider authentication.&amp;lt;br&amp;gt;&lt;br /&gt;
Authlogic&amp;lt;ref&amp;gt;https://github.com/binarylogic/authlogic&amp;lt;/ref&amp;gt;: A clean, simple, and unobtrusive ruby authentication solution.&amp;lt;br&amp;gt;&lt;br /&gt;
Restful-authentication&amp;lt;ref&amp;gt;https://github.com/technoweenie/restful-authentication&amp;lt;/ref&amp;gt;: Generates common user authentication code for Rails/Merb, with a full test/unit and rspec suite and optional Acts as State Machine support built-in.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Devise is the most popular Rails Authentication tools. It provides a full gamut of features, and can be configured to meet most requirements. Devise often interacts with Warden which does not provide helper methods, controller classes, views, configuration options and log in failure handling. All of these things are what Devise supplies. So if you need to extend or augment Devise, you may need to implement a customized Strategy class for your own.&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94213</id>
		<title>User:Mdong3</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94213"/>
		<updated>2015-02-18T17:52:54Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Setup Devise */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;6&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Devise&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Devise &amp;lt;ref&amp;gt;https://github.com/plataformatec/devise&amp;lt;/ref&amp;gt;''' is a Rails gem used for authenticating and managing users. &lt;br /&gt;
&lt;br /&gt;
The topic write up for this page can be found [https://docs.google.com/a/ncsu.edu/document/d/1Ay5OOUkcLMC-FH61fAm3cNvB3Uyk2hJ09vHnRgqwL-k/edit here].&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
=== Security Background===&lt;br /&gt;
Web applications are relatively easy to attack, as they are simple to understand and manipulate. The Gartner Group estimates that 75% of attacks are at the web application layer, and found out &amp;quot;that out of 300 audited sites, 97% are vulnerable to attack&amp;quot;&amp;lt;ref&amp;gt;http://www.primeon.com/press/article001.php&amp;lt;/ref&amp;gt;.Security depends on the people using the framework, and sometimes on the development method. &lt;br /&gt;
There are several ways to ensure security: Encryption, LDAP, Rails Authentication, Rails Authorization, Rails Captcha, Security Tools and Spam Detection. And devise is for Rails Authentication.&lt;br /&gt;
&lt;br /&gt;
===User Authentication Process ===&lt;br /&gt;
User Authentication is responsible for the following actions:  &lt;br /&gt;
*Signup: create a new user. This user will have to register with a username, password (which will be encrypted in the database), email, and other relevant details. &lt;br /&gt;
*Login: allow a user to sign in with her/his valid username and password. The authentication process happens by matching the username and password in the database, allowing the user access to the protected actions only if the given information matches the recorded values successfully. If not, the user will be redirected to the login page again.&lt;br /&gt;
*Access Restriction: create a session to hold the authenticated user ID after login, so navigation through additional protected actions can be done easily by just checking the userID in the current session.&lt;br /&gt;
*Logout: allow the user to sign out and set the authenticated userID in session file to nil.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Started ==&lt;br /&gt;
===Devise===&lt;br /&gt;
Devise is a flexible authentication solution for Rails helping developers save  time and effort while implementing authentication mechanisms from start. User authentication is a major component of most of the web applications, primarily to determine if the user is in fact, who it is declared to be. Devise is based on Warden&amp;lt;ref&amp;gt;https://github.com/hassox/warden/wiki&amp;lt;/ref&amp;gt;. (Customized [https://github.com/rack/rack Rack] middleware that provides authentication for rack applications). Rack can be considered a middleware between web server such as Mongreal, WEBrick and frameworks such as Rails, Sinatra. &amp;lt;br&amp;gt; &lt;br /&gt;
Current Version: 3.4.1&amp;lt;br&amp;gt;&lt;br /&gt;
First Release: 5 years ago&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Devise===&lt;br /&gt;
Once you have created a Rails app using the &amp;quot;rails new &amp;lt;app name&amp;gt;&amp;quot; command we first need to add a line to the &amp;quot;Gemfile&amp;quot; using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;gem 'devise'&amp;quot; &amp;gt;&amp;gt; Gemfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then install the gem using:&lt;br /&gt;
&amp;lt;pre&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
The Gem will be installed for your rails application. Then run the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:install          &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create config files.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise user              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To create model(User) class and routes and to also associate the 'User' model with 'Devise'.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:migrate                        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To run the migration and create the table with certain fields appropriate for user authentication. The result should be something like: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrating ================================&lt;br /&gt;
-- create_table(:users)&lt;br /&gt;
   -&amp;gt; 0.0178s&lt;br /&gt;
-- add_index(:users, :email, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0010s&lt;br /&gt;
-- add_index(:users, :reset_password_token, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0055s&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrated (0.0255s) =======================&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:views users      &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create the directory /app/views/users with all the devise views, such as login form, registration form .&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Devise Methods==&lt;br /&gt;
Devise provides classes, models, views, controllers, views, helpers, routes. However, these functionality are exposed in only a small number of helper methods,   not all of these components would be required to know. Some of the important Devise helper methods provided are:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Method: authenticate_user!====&lt;br /&gt;
The &amp;lt;i&amp;gt;authenticate_user!&amp;lt;/i&amp;gt; method is a class method that can be called from a controller only. The method determines if the user has access to all or a specific set of controller actions. This method is invoked via a &amp;lt;i&amp;gt;before_filter&amp;lt;/i&amp;gt;, for example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;to make make any exceptions for accessing any actions without authentications we can update the above statement as:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before_action :authenticate_user!, except: [:show]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above example, user authentication would be required to call any actions in the controller except the &amp;lt;i&amp;gt;show&amp;lt;/i&amp;gt; action. &lt;br /&gt;
So if the &amp;lt;i&amp;gt;root&amp;lt;/i&amp;gt; in the &amp;lt;code&amp;gt;config/routes.rb&amp;lt;/code&amp;gt; field is set to obtain any view belonging to the UsersController in this case, the Sign in page will be loaded before any of the actions can be accessed. &amp;lt;br&amp;gt; Once the user is authenticate, the required action is obtained.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: current_user====&lt;br /&gt;
The &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method is used to return the model class to whom the signed in user belongs. The method returns nil if a user has not yet signed in. &lt;br /&gt;
The &amp;lt;authenticate_user!&amp;gt; will make sure that the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method would never return &amp;lt;i&amp;gt;nil&amp;lt;/i&amp;gt;. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_signed_in?====&lt;br /&gt;
Checks if the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method returns a non nil value. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: sign_in(@user) and sign_out(@user)====&lt;br /&gt;
The sign_in(@user) and the sign_out(@user) are useful to login or logout a newly created user.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_session====&lt;br /&gt;
This method returns metadata regarding the logged in user.&lt;br /&gt;
&lt;br /&gt;
==Devise Modules==&lt;br /&gt;
===Database Authenticatable===&lt;br /&gt;
Ensures that the user has entered the correct password and also to encrypt and stores the password in the database when the user registers for the first time. The authentication can be done both through POST requests or HTTP Basic Authentication.&amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).valid_password?('password123')         # returns true/false &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Omniauthable===&lt;br /&gt;
Adds OmniAuth (https://github.com/intridea/omniauth) support.&amp;lt;br&amp;gt;&lt;br /&gt;
===Confirmable===&lt;br /&gt;
Sends confirmation emails to Users following successful registration. This is to prevent bot registrations. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).confirm!      # returns true unless it's already confirmed&lt;br /&gt;
User.find(1).confirmed?    # true/false&lt;br /&gt;
User.find(1).send_confirmation_instructions # manually send instructions&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Recoverable===&lt;br /&gt;
Resets the user password and sends reset instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;# resets the user password and save the record, true if valid passwords are given, otherwise false&lt;br /&gt;
User.find(1).reset_password!('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# only resets the user password, without saving the record&lt;br /&gt;
user = User.find(1)&lt;br /&gt;
user.reset_password('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# creates a new token and send it with instructions about how to reset the password&lt;br /&gt;
User.find(1).send_reset_password_instructions &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Registerable===&lt;br /&gt;
Handles signing up users through a registration process, also allowing them to edit and destroy their account.&amp;lt;br&amp;gt;&lt;br /&gt;
Helps user to register themselves and also to make changes to their login credentials including deleting their account. &lt;br /&gt;
===Rememberable=== &lt;br /&gt;
Cookie handling module to manage generating and clearing of tokens for remembering the user.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;User.find(1).remember_me!  # regenerating the token&lt;br /&gt;
User.find(1).forget_me!    # clearing the token&lt;br /&gt;
&lt;br /&gt;
# generating info to put into cookies&lt;br /&gt;
User.serialize_into_cookie(user)&lt;br /&gt;
&lt;br /&gt;
# lookup the user based on the incoming cookie information&lt;br /&gt;
User.serialize_from_cookie(cookie_string)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trackable=== &lt;br /&gt;
Tracks login details for a specific user using log in count, last log in, IP address. These details help Site admin to investigate any unusual activity.&amp;lt;br&amp;gt; &lt;br /&gt;
===Timeoutable===&lt;br /&gt;
Expires sessions that have not been active in a specified period of time.&amp;lt;br&amp;gt;&lt;br /&gt;
===Validatable===&lt;br /&gt;
Provides validations of email and password to make sure that the log in details follow a given format. These can be modified to have customized validations.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;#email_required? ⇒ Boolean protected&lt;br /&gt;
#password_required? ⇒ Boolean protected&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Lockable===&lt;br /&gt;
Locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example applications ==&lt;br /&gt;
=== Devise and Rails&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
Rails 4.2 starter app with Devise for authentication.&lt;br /&gt;
====What is implemented====&lt;br /&gt;
&amp;amp;bull; Home page&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Navigation bar&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Sign up (create account)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Login&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Forgot password?” feature&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Remember me” (stay logged in) feature&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Edit account (edit user profile)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; List of users&amp;lt;br&amp;gt;&lt;br /&gt;
==== Installing ====&lt;br /&gt;
To build the example application, run:&lt;br /&gt;
&amp;lt;pre&amp;gt;rails new rails-devise -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will create a Rails app named &amp;lt;code&amp;gt;rails-devise&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
Then, select “Build a RailsApps example application”. After that, select”6) rails-devise”.&amp;lt;br&amp;gt;&lt;br /&gt;
As for additional preferences:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; If you plan to deploy to Heroku, select “Unicorn&amp;quot; as your production web server.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Use “SQLite&amp;quot; for development on Mac or Linux. If you plan to deploy to Heroku, use “PostgreSQL&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; The example application uses the default “ERB” Rails template engine.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; If you are a beginner, for test framework, select “None”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; if you choose either “Foundation&amp;quot; or “Bootstrap&amp;quot;, it will automatically install Devise views with attractive styling.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Gmail&amp;quot; is for development if you have one. if your site will be heavily used, then choose “SendGrid&amp;quot; or “Mandrill&amp;quot; for production.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; The example uses &amp;quot;Devise with default modules&amp;quot;.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Devise and Pundit and Rails&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise-pundit&amp;lt;/ref&amp;gt;===&lt;br /&gt;
It extends the rails-devise example application to add authorization with Pundit.&lt;br /&gt;
====What is implemented====&lt;br /&gt;
It adds authorization with Pundit, showing how to implement user roles, and limit access to pages based on user role.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an admin can see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an admin can change a user’s role&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t change their role&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t see (or edit) another user’s profile&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can see (and edit) their own user profile&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Installing====&lt;br /&gt;
To build the example application, run:&lt;br /&gt;
&amp;lt;pre&amp;gt;rails new rails-devise-pundit -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will create a new Rails app named &amp;lt;code&amp;gt;rails-devise-pundit&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
Then, select “Build a RailsApps example application”. After that, select ”8) rails-devise-pundit”.&amp;lt;br&amp;gt;&lt;br /&gt;
The following steps are the same as Devise and Rails.&lt;br /&gt;
&lt;br /&gt;
==other Rails Authentication==&lt;br /&gt;
OmniAuth&amp;lt;ref&amp;gt;https://github.com/intridea/omniauth&amp;lt;/ref&amp;gt;: A generalized Rack framework for multiple-provider authentication.&amp;lt;br&amp;gt;&lt;br /&gt;
Authlogic&amp;lt;ref&amp;gt;https://github.com/binarylogic/authlogic&amp;lt;/ref&amp;gt;: A clean, simple, and unobtrusive ruby authentication solution.&amp;lt;br&amp;gt;&lt;br /&gt;
Restful-authentication&amp;lt;ref&amp;gt;https://github.com/technoweenie/restful-authentication&amp;lt;/ref&amp;gt;: Generates common user authentication code for Rails/Merb, with a full test/unit and rspec suite and optional Acts as State Machine support built-in.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Devise is the most popular Rails Authentication tools. It provides a full gamut of features, and can be configured to meet most requirements. Devise often interacts with Warden which does not provide helper methods, controller classes, views, configuration options and log in failure handling. All of these things are what Devise supplies. So if you need to extend or augment Devise, you may need to implement a customized Strategy class for your own.&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94212</id>
		<title>User:Mdong3</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94212"/>
		<updated>2015-02-18T17:52:32Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Setup Devise */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;6&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Devise&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Devise &amp;lt;ref&amp;gt;https://github.com/plataformatec/devise&amp;lt;/ref&amp;gt;''' is a Rails gem used for authenticating and managing users. &lt;br /&gt;
&lt;br /&gt;
The topic write up for this page can be found [https://docs.google.com/a/ncsu.edu/document/d/1Ay5OOUkcLMC-FH61fAm3cNvB3Uyk2hJ09vHnRgqwL-k/edit here].&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
=== Security Background===&lt;br /&gt;
Web applications are relatively easy to attack, as they are simple to understand and manipulate. The Gartner Group estimates that 75% of attacks are at the web application layer, and found out &amp;quot;that out of 300 audited sites, 97% are vulnerable to attack&amp;quot;&amp;lt;ref&amp;gt;http://www.primeon.com/press/article001.php&amp;lt;/ref&amp;gt;.Security depends on the people using the framework, and sometimes on the development method. &lt;br /&gt;
There are several ways to ensure security: Encryption, LDAP, Rails Authentication, Rails Authorization, Rails Captcha, Security Tools and Spam Detection. And devise is for Rails Authentication.&lt;br /&gt;
&lt;br /&gt;
===User Authentication Process ===&lt;br /&gt;
User Authentication is responsible for the following actions:  &lt;br /&gt;
*Signup: create a new user. This user will have to register with a username, password (which will be encrypted in the database), email, and other relevant details. &lt;br /&gt;
*Login: allow a user to sign in with her/his valid username and password. The authentication process happens by matching the username and password in the database, allowing the user access to the protected actions only if the given information matches the recorded values successfully. If not, the user will be redirected to the login page again.&lt;br /&gt;
*Access Restriction: create a session to hold the authenticated user ID after login, so navigation through additional protected actions can be done easily by just checking the userID in the current session.&lt;br /&gt;
*Logout: allow the user to sign out and set the authenticated userID in session file to nil.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Started ==&lt;br /&gt;
===Devise===&lt;br /&gt;
Devise is a flexible authentication solution for Rails helping developers save  time and effort while implementing authentication mechanisms from start. User authentication is a major component of most of the web applications, primarily to determine if the user is in fact, who it is declared to be. Devise is based on Warden&amp;lt;ref&amp;gt;https://github.com/hassox/warden/wiki&amp;lt;/ref&amp;gt;. (Customized [https://github.com/rack/rack Rack] middleware that provides authentication for rack applications). Rack can be considered a middleware between web server such as Mongreal, WEBrick and frameworks such as Rails, Sinatra. &amp;lt;br&amp;gt; &lt;br /&gt;
Current Version: 3.4.1&amp;lt;br&amp;gt;&lt;br /&gt;
First Release: 5 years ago&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Devise===&lt;br /&gt;
Once you have created a Rails app using the &amp;quot;rails new &amp;lt;app name&amp;gt;&amp;quot; command we first need to add a line to the &amp;quot;Gemfile&amp;quot; using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;gem 'devise'&amp;quot; &amp;gt;&amp;gt; Gemfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then install the gem using:&lt;br /&gt;
&amp;lt;pre&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
The Gem will be installed for your rails application. Then run the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:install          &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create config files.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise user              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To create model(User) class and routes and to also associate the 'User' model with 'Devise'.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:migrate                        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To run the migration and create the table with certain fields appropriate for user authentication. The result should be something like: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrating ================================&lt;br /&gt;
-- create_table(:users)&lt;br /&gt;
   -&amp;gt; 0.0178s&lt;br /&gt;
-- add_index(:users, :email, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0010s&lt;br /&gt;
-- add_index(:users, :reset_password_token, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0055s&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrated (0.0255s) =======================&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:views users      &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create the directory /app/views/users with all the devise views, such as login form, registration form .&lt;br /&gt;
&lt;br /&gt;
==Devise Methods==&lt;br /&gt;
Devise provides classes, models, views, controllers, views, helpers, routes. However, these functionality are exposed in only a small number of helper methods,   not all of these components would be required to know. Some of the important Devise helper methods provided are:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Method: authenticate_user!====&lt;br /&gt;
The &amp;lt;i&amp;gt;authenticate_user!&amp;lt;/i&amp;gt; method is a class method that can be called from a controller only. The method determines if the user has access to all or a specific set of controller actions. This method is invoked via a &amp;lt;i&amp;gt;before_filter&amp;lt;/i&amp;gt;, for example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;to make make any exceptions for accessing any actions without authentications we can update the above statement as:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before_action :authenticate_user!, except: [:show]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above example, user authentication would be required to call any actions in the controller except the &amp;lt;i&amp;gt;show&amp;lt;/i&amp;gt; action. &lt;br /&gt;
So if the &amp;lt;i&amp;gt;root&amp;lt;/i&amp;gt; in the &amp;lt;code&amp;gt;config/routes.rb&amp;lt;/code&amp;gt; field is set to obtain any view belonging to the UsersController in this case, the Sign in page will be loaded before any of the actions can be accessed. &amp;lt;br&amp;gt; Once the user is authenticate, the required action is obtained.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: current_user====&lt;br /&gt;
The &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method is used to return the model class to whom the signed in user belongs. The method returns nil if a user has not yet signed in. &lt;br /&gt;
The &amp;lt;authenticate_user!&amp;gt; will make sure that the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method would never return &amp;lt;i&amp;gt;nil&amp;lt;/i&amp;gt;. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_signed_in?====&lt;br /&gt;
Checks if the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method returns a non nil value. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: sign_in(@user) and sign_out(@user)====&lt;br /&gt;
The sign_in(@user) and the sign_out(@user) are useful to login or logout a newly created user.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_session====&lt;br /&gt;
This method returns metadata regarding the logged in user.&lt;br /&gt;
&lt;br /&gt;
==Devise Modules==&lt;br /&gt;
===Database Authenticatable===&lt;br /&gt;
Ensures that the user has entered the correct password and also to encrypt and stores the password in the database when the user registers for the first time. The authentication can be done both through POST requests or HTTP Basic Authentication.&amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).valid_password?('password123')         # returns true/false &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Omniauthable===&lt;br /&gt;
Adds OmniAuth (https://github.com/intridea/omniauth) support.&amp;lt;br&amp;gt;&lt;br /&gt;
===Confirmable===&lt;br /&gt;
Sends confirmation emails to Users following successful registration. This is to prevent bot registrations. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).confirm!      # returns true unless it's already confirmed&lt;br /&gt;
User.find(1).confirmed?    # true/false&lt;br /&gt;
User.find(1).send_confirmation_instructions # manually send instructions&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Recoverable===&lt;br /&gt;
Resets the user password and sends reset instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;# resets the user password and save the record, true if valid passwords are given, otherwise false&lt;br /&gt;
User.find(1).reset_password!('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# only resets the user password, without saving the record&lt;br /&gt;
user = User.find(1)&lt;br /&gt;
user.reset_password('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# creates a new token and send it with instructions about how to reset the password&lt;br /&gt;
User.find(1).send_reset_password_instructions &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Registerable===&lt;br /&gt;
Handles signing up users through a registration process, also allowing them to edit and destroy their account.&amp;lt;br&amp;gt;&lt;br /&gt;
Helps user to register themselves and also to make changes to their login credentials including deleting their account. &lt;br /&gt;
===Rememberable=== &lt;br /&gt;
Cookie handling module to manage generating and clearing of tokens for remembering the user.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;User.find(1).remember_me!  # regenerating the token&lt;br /&gt;
User.find(1).forget_me!    # clearing the token&lt;br /&gt;
&lt;br /&gt;
# generating info to put into cookies&lt;br /&gt;
User.serialize_into_cookie(user)&lt;br /&gt;
&lt;br /&gt;
# lookup the user based on the incoming cookie information&lt;br /&gt;
User.serialize_from_cookie(cookie_string)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trackable=== &lt;br /&gt;
Tracks login details for a specific user using log in count, last log in, IP address. These details help Site admin to investigate any unusual activity.&amp;lt;br&amp;gt; &lt;br /&gt;
===Timeoutable===&lt;br /&gt;
Expires sessions that have not been active in a specified period of time.&amp;lt;br&amp;gt;&lt;br /&gt;
===Validatable===&lt;br /&gt;
Provides validations of email and password to make sure that the log in details follow a given format. These can be modified to have customized validations.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;#email_required? ⇒ Boolean protected&lt;br /&gt;
#password_required? ⇒ Boolean protected&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Lockable===&lt;br /&gt;
Locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example applications ==&lt;br /&gt;
=== Devise and Rails&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
Rails 4.2 starter app with Devise for authentication.&lt;br /&gt;
====What is implemented====&lt;br /&gt;
&amp;amp;bull; Home page&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Navigation bar&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Sign up (create account)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Login&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Forgot password?” feature&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Remember me” (stay logged in) feature&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Edit account (edit user profile)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; List of users&amp;lt;br&amp;gt;&lt;br /&gt;
==== Installing ====&lt;br /&gt;
To build the example application, run:&lt;br /&gt;
&amp;lt;pre&amp;gt;rails new rails-devise -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will create a Rails app named &amp;lt;code&amp;gt;rails-devise&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
Then, select “Build a RailsApps example application”. After that, select”6) rails-devise”.&amp;lt;br&amp;gt;&lt;br /&gt;
As for additional preferences:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; If you plan to deploy to Heroku, select “Unicorn&amp;quot; as your production web server.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Use “SQLite&amp;quot; for development on Mac or Linux. If you plan to deploy to Heroku, use “PostgreSQL&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; The example application uses the default “ERB” Rails template engine.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; If you are a beginner, for test framework, select “None”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; if you choose either “Foundation&amp;quot; or “Bootstrap&amp;quot;, it will automatically install Devise views with attractive styling.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Gmail&amp;quot; is for development if you have one. if your site will be heavily used, then choose “SendGrid&amp;quot; or “Mandrill&amp;quot; for production.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; The example uses &amp;quot;Devise with default modules&amp;quot;.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Devise and Pundit and Rails&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise-pundit&amp;lt;/ref&amp;gt;===&lt;br /&gt;
It extends the rails-devise example application to add authorization with Pundit.&lt;br /&gt;
====What is implemented====&lt;br /&gt;
It adds authorization with Pundit, showing how to implement user roles, and limit access to pages based on user role.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an admin can see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an admin can change a user’s role&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t change their role&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t see (or edit) another user’s profile&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can see (and edit) their own user profile&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Installing====&lt;br /&gt;
To build the example application, run:&lt;br /&gt;
&amp;lt;pre&amp;gt;rails new rails-devise-pundit -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will create a new Rails app named &amp;lt;code&amp;gt;rails-devise-pundit&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
Then, select “Build a RailsApps example application”. After that, select ”8) rails-devise-pundit”.&amp;lt;br&amp;gt;&lt;br /&gt;
The following steps are the same as Devise and Rails.&lt;br /&gt;
&lt;br /&gt;
==other Rails Authentication==&lt;br /&gt;
OmniAuth&amp;lt;ref&amp;gt;https://github.com/intridea/omniauth&amp;lt;/ref&amp;gt;: A generalized Rack framework for multiple-provider authentication.&amp;lt;br&amp;gt;&lt;br /&gt;
Authlogic&amp;lt;ref&amp;gt;https://github.com/binarylogic/authlogic&amp;lt;/ref&amp;gt;: A clean, simple, and unobtrusive ruby authentication solution.&amp;lt;br&amp;gt;&lt;br /&gt;
Restful-authentication&amp;lt;ref&amp;gt;https://github.com/technoweenie/restful-authentication&amp;lt;/ref&amp;gt;: Generates common user authentication code for Rails/Merb, with a full test/unit and rspec suite and optional Acts as State Machine support built-in.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Devise is the most popular Rails Authentication tools. It provides a full gamut of features, and can be configured to meet most requirements. Devise often interacts with Warden which does not provide helper methods, controller classes, views, configuration options and log in failure handling. All of these things are what Devise supplies. So if you need to extend or augment Devise, you may need to implement a customized Strategy class for your own.&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94211</id>
		<title>User:Mdong3</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94211"/>
		<updated>2015-02-18T17:52:09Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Setup Devise */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;6&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Devise&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Devise &amp;lt;ref&amp;gt;https://github.com/plataformatec/devise&amp;lt;/ref&amp;gt;''' is a Rails gem used for authenticating and managing users. &lt;br /&gt;
&lt;br /&gt;
The topic write up for this page can be found [https://docs.google.com/a/ncsu.edu/document/d/1Ay5OOUkcLMC-FH61fAm3cNvB3Uyk2hJ09vHnRgqwL-k/edit here].&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
=== Security Background===&lt;br /&gt;
Web applications are relatively easy to attack, as they are simple to understand and manipulate. The Gartner Group estimates that 75% of attacks are at the web application layer, and found out &amp;quot;that out of 300 audited sites, 97% are vulnerable to attack&amp;quot;&amp;lt;ref&amp;gt;http://www.primeon.com/press/article001.php&amp;lt;/ref&amp;gt;.Security depends on the people using the framework, and sometimes on the development method. &lt;br /&gt;
There are several ways to ensure security: Encryption, LDAP, Rails Authentication, Rails Authorization, Rails Captcha, Security Tools and Spam Detection. And devise is for Rails Authentication.&lt;br /&gt;
&lt;br /&gt;
===User Authentication Process ===&lt;br /&gt;
User Authentication is responsible for the following actions:  &lt;br /&gt;
*Signup: create a new user. This user will have to register with a username, password (which will be encrypted in the database), email, and other relevant details. &lt;br /&gt;
*Login: allow a user to sign in with her/his valid username and password. The authentication process happens by matching the username and password in the database, allowing the user access to the protected actions only if the given information matches the recorded values successfully. If not, the user will be redirected to the login page again.&lt;br /&gt;
*Access Restriction: create a session to hold the authenticated user ID after login, so navigation through additional protected actions can be done easily by just checking the userID in the current session.&lt;br /&gt;
*Logout: allow the user to sign out and set the authenticated userID in session file to nil.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Started ==&lt;br /&gt;
===Devise===&lt;br /&gt;
Devise is a flexible authentication solution for Rails helping developers save  time and effort while implementing authentication mechanisms from start. User authentication is a major component of most of the web applications, primarily to determine if the user is in fact, who it is declared to be. Devise is based on Warden&amp;lt;ref&amp;gt;https://github.com/hassox/warden/wiki&amp;lt;/ref&amp;gt;. (Customized [https://github.com/rack/rack Rack] middleware that provides authentication for rack applications). Rack can be considered a middleware between web server such as Mongreal, WEBrick and frameworks such as Rails, Sinatra. &amp;lt;br&amp;gt; &lt;br /&gt;
Current Version: 3.4.1&amp;lt;br&amp;gt;&lt;br /&gt;
First Release: 5 years ago&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Devise===&lt;br /&gt;
Once you have created a Rails app using the &amp;quot;rails new &amp;lt;app name&amp;gt;&amp;quot; command we first need to add a line to the &amp;quot;Gemfile&amp;quot; using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;gem 'devise'&amp;quot; &amp;gt;&amp;gt; Gemfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then install the gem using:&lt;br /&gt;
&amp;lt;pre&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
The Gem will be installed for your rails application. Then run the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:install          &lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To create config files.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise user              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To create model(User) class and routes and to also associate the 'User' model with 'Devise'.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:migrate                        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To run the migration and create the table with certain fields appropriate for user authentication. The result should be something like: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrating ================================&lt;br /&gt;
-- create_table(:users)&lt;br /&gt;
   -&amp;gt; 0.0178s&lt;br /&gt;
-- add_index(:users, :email, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0010s&lt;br /&gt;
-- add_index(:users, :reset_password_token, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0055s&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrated (0.0255s) =======================&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:views users      &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create the directory /app/views/users with all the devise views, such as login form, registration form .&lt;br /&gt;
&lt;br /&gt;
==Devise Methods==&lt;br /&gt;
Devise provides classes, models, views, controllers, views, helpers, routes. However, these functionality are exposed in only a small number of helper methods,   not all of these components would be required to know. Some of the important Devise helper methods provided are:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Method: authenticate_user!====&lt;br /&gt;
The &amp;lt;i&amp;gt;authenticate_user!&amp;lt;/i&amp;gt; method is a class method that can be called from a controller only. The method determines if the user has access to all or a specific set of controller actions. This method is invoked via a &amp;lt;i&amp;gt;before_filter&amp;lt;/i&amp;gt;, for example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;to make make any exceptions for accessing any actions without authentications we can update the above statement as:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before_action :authenticate_user!, except: [:show]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above example, user authentication would be required to call any actions in the controller except the &amp;lt;i&amp;gt;show&amp;lt;/i&amp;gt; action. &lt;br /&gt;
So if the &amp;lt;i&amp;gt;root&amp;lt;/i&amp;gt; in the &amp;lt;code&amp;gt;config/routes.rb&amp;lt;/code&amp;gt; field is set to obtain any view belonging to the UsersController in this case, the Sign in page will be loaded before any of the actions can be accessed. &amp;lt;br&amp;gt; Once the user is authenticate, the required action is obtained.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: current_user====&lt;br /&gt;
The &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method is used to return the model class to whom the signed in user belongs. The method returns nil if a user has not yet signed in. &lt;br /&gt;
The &amp;lt;authenticate_user!&amp;gt; will make sure that the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method would never return &amp;lt;i&amp;gt;nil&amp;lt;/i&amp;gt;. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_signed_in?====&lt;br /&gt;
Checks if the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method returns a non nil value. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: sign_in(@user) and sign_out(@user)====&lt;br /&gt;
The sign_in(@user) and the sign_out(@user) are useful to login or logout a newly created user.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_session====&lt;br /&gt;
This method returns metadata regarding the logged in user.&lt;br /&gt;
&lt;br /&gt;
==Devise Modules==&lt;br /&gt;
===Database Authenticatable===&lt;br /&gt;
Ensures that the user has entered the correct password and also to encrypt and stores the password in the database when the user registers for the first time. The authentication can be done both through POST requests or HTTP Basic Authentication.&amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).valid_password?('password123')         # returns true/false &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Omniauthable===&lt;br /&gt;
Adds OmniAuth (https://github.com/intridea/omniauth) support.&amp;lt;br&amp;gt;&lt;br /&gt;
===Confirmable===&lt;br /&gt;
Sends confirmation emails to Users following successful registration. This is to prevent bot registrations. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).confirm!      # returns true unless it's already confirmed&lt;br /&gt;
User.find(1).confirmed?    # true/false&lt;br /&gt;
User.find(1).send_confirmation_instructions # manually send instructions&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Recoverable===&lt;br /&gt;
Resets the user password and sends reset instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;# resets the user password and save the record, true if valid passwords are given, otherwise false&lt;br /&gt;
User.find(1).reset_password!('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# only resets the user password, without saving the record&lt;br /&gt;
user = User.find(1)&lt;br /&gt;
user.reset_password('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# creates a new token and send it with instructions about how to reset the password&lt;br /&gt;
User.find(1).send_reset_password_instructions &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Registerable===&lt;br /&gt;
Handles signing up users through a registration process, also allowing them to edit and destroy their account.&amp;lt;br&amp;gt;&lt;br /&gt;
Helps user to register themselves and also to make changes to their login credentials including deleting their account. &lt;br /&gt;
===Rememberable=== &lt;br /&gt;
Cookie handling module to manage generating and clearing of tokens for remembering the user.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;User.find(1).remember_me!  # regenerating the token&lt;br /&gt;
User.find(1).forget_me!    # clearing the token&lt;br /&gt;
&lt;br /&gt;
# generating info to put into cookies&lt;br /&gt;
User.serialize_into_cookie(user)&lt;br /&gt;
&lt;br /&gt;
# lookup the user based on the incoming cookie information&lt;br /&gt;
User.serialize_from_cookie(cookie_string)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trackable=== &lt;br /&gt;
Tracks login details for a specific user using log in count, last log in, IP address. These details help Site admin to investigate any unusual activity.&amp;lt;br&amp;gt; &lt;br /&gt;
===Timeoutable===&lt;br /&gt;
Expires sessions that have not been active in a specified period of time.&amp;lt;br&amp;gt;&lt;br /&gt;
===Validatable===&lt;br /&gt;
Provides validations of email and password to make sure that the log in details follow a given format. These can be modified to have customized validations.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;#email_required? ⇒ Boolean protected&lt;br /&gt;
#password_required? ⇒ Boolean protected&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Lockable===&lt;br /&gt;
Locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example applications ==&lt;br /&gt;
=== Devise and Rails&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
Rails 4.2 starter app with Devise for authentication.&lt;br /&gt;
====What is implemented====&lt;br /&gt;
&amp;amp;bull; Home page&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Navigation bar&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Sign up (create account)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Login&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Forgot password?” feature&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Remember me” (stay logged in) feature&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Edit account (edit user profile)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; List of users&amp;lt;br&amp;gt;&lt;br /&gt;
==== Installing ====&lt;br /&gt;
To build the example application, run:&lt;br /&gt;
&amp;lt;pre&amp;gt;rails new rails-devise -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will create a Rails app named &amp;lt;code&amp;gt;rails-devise&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
Then, select “Build a RailsApps example application”. After that, select”6) rails-devise”.&amp;lt;br&amp;gt;&lt;br /&gt;
As for additional preferences:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; If you plan to deploy to Heroku, select “Unicorn&amp;quot; as your production web server.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Use “SQLite&amp;quot; for development on Mac or Linux. If you plan to deploy to Heroku, use “PostgreSQL&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; The example application uses the default “ERB” Rails template engine.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; If you are a beginner, for test framework, select “None”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; if you choose either “Foundation&amp;quot; or “Bootstrap&amp;quot;, it will automatically install Devise views with attractive styling.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Gmail&amp;quot; is for development if you have one. if your site will be heavily used, then choose “SendGrid&amp;quot; or “Mandrill&amp;quot; for production.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; The example uses &amp;quot;Devise with default modules&amp;quot;.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Devise and Pundit and Rails&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise-pundit&amp;lt;/ref&amp;gt;===&lt;br /&gt;
It extends the rails-devise example application to add authorization with Pundit.&lt;br /&gt;
====What is implemented====&lt;br /&gt;
It adds authorization with Pundit, showing how to implement user roles, and limit access to pages based on user role.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an admin can see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an admin can change a user’s role&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t change their role&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t see (or edit) another user’s profile&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can see (and edit) their own user profile&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Installing====&lt;br /&gt;
To build the example application, run:&lt;br /&gt;
&amp;lt;pre&amp;gt;rails new rails-devise-pundit -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will create a new Rails app named &amp;lt;code&amp;gt;rails-devise-pundit&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
Then, select “Build a RailsApps example application”. After that, select ”8) rails-devise-pundit”.&amp;lt;br&amp;gt;&lt;br /&gt;
The following steps are the same as Devise and Rails.&lt;br /&gt;
&lt;br /&gt;
==other Rails Authentication==&lt;br /&gt;
OmniAuth&amp;lt;ref&amp;gt;https://github.com/intridea/omniauth&amp;lt;/ref&amp;gt;: A generalized Rack framework for multiple-provider authentication.&amp;lt;br&amp;gt;&lt;br /&gt;
Authlogic&amp;lt;ref&amp;gt;https://github.com/binarylogic/authlogic&amp;lt;/ref&amp;gt;: A clean, simple, and unobtrusive ruby authentication solution.&amp;lt;br&amp;gt;&lt;br /&gt;
Restful-authentication&amp;lt;ref&amp;gt;https://github.com/technoweenie/restful-authentication&amp;lt;/ref&amp;gt;: Generates common user authentication code for Rails/Merb, with a full test/unit and rspec suite and optional Acts as State Machine support built-in.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Devise is the most popular Rails Authentication tools. It provides a full gamut of features, and can be configured to meet most requirements. Devise often interacts with Warden which does not provide helper methods, controller classes, views, configuration options and log in failure handling. All of these things are what Devise supplies. So if you need to extend or augment Devise, you may need to implement a customized Strategy class for your own.&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94210</id>
		<title>User:Mdong3</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94210"/>
		<updated>2015-02-18T17:51:33Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Setup Devise */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;6&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Devise&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Devise &amp;lt;ref&amp;gt;https://github.com/plataformatec/devise&amp;lt;/ref&amp;gt;''' is a Rails gem used for authenticating and managing users. &lt;br /&gt;
&lt;br /&gt;
The topic write up for this page can be found [https://docs.google.com/a/ncsu.edu/document/d/1Ay5OOUkcLMC-FH61fAm3cNvB3Uyk2hJ09vHnRgqwL-k/edit here].&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
=== Security Background===&lt;br /&gt;
Web applications are relatively easy to attack, as they are simple to understand and manipulate. The Gartner Group estimates that 75% of attacks are at the web application layer, and found out &amp;quot;that out of 300 audited sites, 97% are vulnerable to attack&amp;quot;&amp;lt;ref&amp;gt;http://www.primeon.com/press/article001.php&amp;lt;/ref&amp;gt;.Security depends on the people using the framework, and sometimes on the development method. &lt;br /&gt;
There are several ways to ensure security: Encryption, LDAP, Rails Authentication, Rails Authorization, Rails Captcha, Security Tools and Spam Detection. And devise is for Rails Authentication.&lt;br /&gt;
&lt;br /&gt;
===User Authentication Process ===&lt;br /&gt;
User Authentication is responsible for the following actions:  &lt;br /&gt;
*Signup: create a new user. This user will have to register with a username, password (which will be encrypted in the database), email, and other relevant details. &lt;br /&gt;
*Login: allow a user to sign in with her/his valid username and password. The authentication process happens by matching the username and password in the database, allowing the user access to the protected actions only if the given information matches the recorded values successfully. If not, the user will be redirected to the login page again.&lt;br /&gt;
*Access Restriction: create a session to hold the authenticated user ID after login, so navigation through additional protected actions can be done easily by just checking the userID in the current session.&lt;br /&gt;
*Logout: allow the user to sign out and set the authenticated userID in session file to nil.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Started ==&lt;br /&gt;
===Devise===&lt;br /&gt;
Devise is a flexible authentication solution for Rails helping developers save  time and effort while implementing authentication mechanisms from start. User authentication is a major component of most of the web applications, primarily to determine if the user is in fact, who it is declared to be. Devise is based on Warden&amp;lt;ref&amp;gt;https://github.com/hassox/warden/wiki&amp;lt;/ref&amp;gt;. (Customized [https://github.com/rack/rack Rack] middleware that provides authentication for rack applications). Rack can be considered a middleware between web server such as Mongreal, WEBrick and frameworks such as Rails, Sinatra. &amp;lt;br&amp;gt; &lt;br /&gt;
Current Version: 3.4.1&amp;lt;br&amp;gt;&lt;br /&gt;
First Release: 5 years ago&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Devise===&lt;br /&gt;
Once you have created a Rails app using the &amp;quot;rails new &amp;lt;app name&amp;gt;&amp;quot; command we first need to add a line to the &amp;quot;Gemfile&amp;quot; using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;gem 'devise'&amp;quot; &amp;gt;&amp;gt; Gemfile&amp;lt;/pre&amp;gt;&lt;br /&gt;
And then install the gem using:&lt;br /&gt;
&amp;lt;pre&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
The Gem will be installed for your rails application. Then run the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:install          &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To create config files.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise user              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To create model(User) class and routes and to also associate the 'User' model with 'Devise'.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:migrate                        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To run the migration and create the table with certain fields appropriate for user authentication. The result should be something like: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrating ================================&lt;br /&gt;
-- create_table(:users)&lt;br /&gt;
   -&amp;gt; 0.0178s&lt;br /&gt;
-- add_index(:users, :email, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0010s&lt;br /&gt;
-- add_index(:users, :reset_password_token, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0055s&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrated (0.0255s) =======================&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:views users      &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create the directory /app/views/users with all the devise views, such as login form, registration form .&lt;br /&gt;
&lt;br /&gt;
==Devise Methods==&lt;br /&gt;
Devise provides classes, models, views, controllers, views, helpers, routes. However, these functionality are exposed in only a small number of helper methods,   not all of these components would be required to know. Some of the important Devise helper methods provided are:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Method: authenticate_user!====&lt;br /&gt;
The &amp;lt;i&amp;gt;authenticate_user!&amp;lt;/i&amp;gt; method is a class method that can be called from a controller only. The method determines if the user has access to all or a specific set of controller actions. This method is invoked via a &amp;lt;i&amp;gt;before_filter&amp;lt;/i&amp;gt;, for example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;to make make any exceptions for accessing any actions without authentications we can update the above statement as:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before_action :authenticate_user!, except: [:show]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above example, user authentication would be required to call any actions in the controller except the &amp;lt;i&amp;gt;show&amp;lt;/i&amp;gt; action. &lt;br /&gt;
So if the &amp;lt;i&amp;gt;root&amp;lt;/i&amp;gt; in the &amp;lt;code&amp;gt;config/routes.rb&amp;lt;/code&amp;gt; field is set to obtain any view belonging to the UsersController in this case, the Sign in page will be loaded before any of the actions can be accessed. &amp;lt;br&amp;gt; Once the user is authenticate, the required action is obtained.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: current_user====&lt;br /&gt;
The &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method is used to return the model class to whom the signed in user belongs. The method returns nil if a user has not yet signed in. &lt;br /&gt;
The &amp;lt;authenticate_user!&amp;gt; will make sure that the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method would never return &amp;lt;i&amp;gt;nil&amp;lt;/i&amp;gt;. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_signed_in?====&lt;br /&gt;
Checks if the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method returns a non nil value. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: sign_in(@user) and sign_out(@user)====&lt;br /&gt;
The sign_in(@user) and the sign_out(@user) are useful to login or logout a newly created user.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_session====&lt;br /&gt;
This method returns metadata regarding the logged in user.&lt;br /&gt;
&lt;br /&gt;
==Devise Modules==&lt;br /&gt;
===Database Authenticatable===&lt;br /&gt;
Ensures that the user has entered the correct password and also to encrypt and stores the password in the database when the user registers for the first time. The authentication can be done both through POST requests or HTTP Basic Authentication.&amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).valid_password?('password123')         # returns true/false &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Omniauthable===&lt;br /&gt;
Adds OmniAuth (https://github.com/intridea/omniauth) support.&amp;lt;br&amp;gt;&lt;br /&gt;
===Confirmable===&lt;br /&gt;
Sends confirmation emails to Users following successful registration. This is to prevent bot registrations. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).confirm!      # returns true unless it's already confirmed&lt;br /&gt;
User.find(1).confirmed?    # true/false&lt;br /&gt;
User.find(1).send_confirmation_instructions # manually send instructions&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Recoverable===&lt;br /&gt;
Resets the user password and sends reset instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;# resets the user password and save the record, true if valid passwords are given, otherwise false&lt;br /&gt;
User.find(1).reset_password!('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# only resets the user password, without saving the record&lt;br /&gt;
user = User.find(1)&lt;br /&gt;
user.reset_password('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# creates a new token and send it with instructions about how to reset the password&lt;br /&gt;
User.find(1).send_reset_password_instructions &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Registerable===&lt;br /&gt;
Handles signing up users through a registration process, also allowing them to edit and destroy their account.&amp;lt;br&amp;gt;&lt;br /&gt;
Helps user to register themselves and also to make changes to their login credentials including deleting their account. &lt;br /&gt;
===Rememberable=== &lt;br /&gt;
Cookie handling module to manage generating and clearing of tokens for remembering the user.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;User.find(1).remember_me!  # regenerating the token&lt;br /&gt;
User.find(1).forget_me!    # clearing the token&lt;br /&gt;
&lt;br /&gt;
# generating info to put into cookies&lt;br /&gt;
User.serialize_into_cookie(user)&lt;br /&gt;
&lt;br /&gt;
# lookup the user based on the incoming cookie information&lt;br /&gt;
User.serialize_from_cookie(cookie_string)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trackable=== &lt;br /&gt;
Tracks login details for a specific user using log in count, last log in, IP address. These details help Site admin to investigate any unusual activity.&amp;lt;br&amp;gt; &lt;br /&gt;
===Timeoutable===&lt;br /&gt;
Expires sessions that have not been active in a specified period of time.&amp;lt;br&amp;gt;&lt;br /&gt;
===Validatable===&lt;br /&gt;
Provides validations of email and password to make sure that the log in details follow a given format. These can be modified to have customized validations.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;#email_required? ⇒ Boolean protected&lt;br /&gt;
#password_required? ⇒ Boolean protected&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Lockable===&lt;br /&gt;
Locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example applications ==&lt;br /&gt;
=== Devise and Rails&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
Rails 4.2 starter app with Devise for authentication.&lt;br /&gt;
====What is implemented====&lt;br /&gt;
&amp;amp;bull; Home page&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Navigation bar&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Sign up (create account)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Login&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Forgot password?” feature&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Remember me” (stay logged in) feature&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Edit account (edit user profile)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; List of users&amp;lt;br&amp;gt;&lt;br /&gt;
==== Installing ====&lt;br /&gt;
To build the example application, run:&lt;br /&gt;
&amp;lt;pre&amp;gt;rails new rails-devise -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will create a Rails app named &amp;lt;code&amp;gt;rails-devise&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
Then, select “Build a RailsApps example application”. After that, select”6) rails-devise”.&amp;lt;br&amp;gt;&lt;br /&gt;
As for additional preferences:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; If you plan to deploy to Heroku, select “Unicorn&amp;quot; as your production web server.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Use “SQLite&amp;quot; for development on Mac or Linux. If you plan to deploy to Heroku, use “PostgreSQL&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; The example application uses the default “ERB” Rails template engine.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; If you are a beginner, for test framework, select “None”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; if you choose either “Foundation&amp;quot; or “Bootstrap&amp;quot;, it will automatically install Devise views with attractive styling.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Gmail&amp;quot; is for development if you have one. if your site will be heavily used, then choose “SendGrid&amp;quot; or “Mandrill&amp;quot; for production.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; The example uses &amp;quot;Devise with default modules&amp;quot;.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Devise and Pundit and Rails&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise-pundit&amp;lt;/ref&amp;gt;===&lt;br /&gt;
It extends the rails-devise example application to add authorization with Pundit.&lt;br /&gt;
====What is implemented====&lt;br /&gt;
It adds authorization with Pundit, showing how to implement user roles, and limit access to pages based on user role.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an admin can see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an admin can change a user’s role&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t change their role&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t see (or edit) another user’s profile&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can see (and edit) their own user profile&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Installing====&lt;br /&gt;
To build the example application, run:&lt;br /&gt;
&amp;lt;pre&amp;gt;rails new rails-devise-pundit -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will create a new Rails app named &amp;lt;code&amp;gt;rails-devise-pundit&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
Then, select “Build a RailsApps example application”. After that, select ”8) rails-devise-pundit”.&amp;lt;br&amp;gt;&lt;br /&gt;
The following steps are the same as Devise and Rails.&lt;br /&gt;
&lt;br /&gt;
==other Rails Authentication==&lt;br /&gt;
OmniAuth&amp;lt;ref&amp;gt;https://github.com/intridea/omniauth&amp;lt;/ref&amp;gt;: A generalized Rack framework for multiple-provider authentication.&amp;lt;br&amp;gt;&lt;br /&gt;
Authlogic&amp;lt;ref&amp;gt;https://github.com/binarylogic/authlogic&amp;lt;/ref&amp;gt;: A clean, simple, and unobtrusive ruby authentication solution.&amp;lt;br&amp;gt;&lt;br /&gt;
Restful-authentication&amp;lt;ref&amp;gt;https://github.com/technoweenie/restful-authentication&amp;lt;/ref&amp;gt;: Generates common user authentication code for Rails/Merb, with a full test/unit and rspec suite and optional Acts as State Machine support built-in.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Devise is the most popular Rails Authentication tools. It provides a full gamut of features, and can be configured to meet most requirements. Devise often interacts with Warden which does not provide helper methods, controller classes, views, configuration options and log in failure handling. All of these things are what Devise supplies. So if you need to extend or augment Devise, you may need to implement a customized Strategy class for your own.&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94208</id>
		<title>User:Mdong3</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=User:Mdong3&amp;diff=94208"/>
		<updated>2015-02-18T17:50:21Z</updated>

		<summary type="html">&lt;p&gt;Savidhal: /* Devise */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;6&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Devise&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Devise &amp;lt;ref&amp;gt;https://github.com/plataformatec/devise&amp;lt;/ref&amp;gt;''' is a Rails gem used for authenticating and managing users. &lt;br /&gt;
&lt;br /&gt;
The topic write up for this page can be found [https://docs.google.com/a/ncsu.edu/document/d/1Ay5OOUkcLMC-FH61fAm3cNvB3Uyk2hJ09vHnRgqwL-k/edit here].&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
=== Security Background===&lt;br /&gt;
Web applications are relatively easy to attack, as they are simple to understand and manipulate. The Gartner Group estimates that 75% of attacks are at the web application layer, and found out &amp;quot;that out of 300 audited sites, 97% are vulnerable to attack&amp;quot;&amp;lt;ref&amp;gt;http://www.primeon.com/press/article001.php&amp;lt;/ref&amp;gt;.Security depends on the people using the framework, and sometimes on the development method. &lt;br /&gt;
There are several ways to ensure security: Encryption, LDAP, Rails Authentication, Rails Authorization, Rails Captcha, Security Tools and Spam Detection. And devise is for Rails Authentication.&lt;br /&gt;
&lt;br /&gt;
===User Authentication Process ===&lt;br /&gt;
User Authentication is responsible for the following actions:  &lt;br /&gt;
*Signup: create a new user. This user will have to register with a username, password (which will be encrypted in the database), email, and other relevant details. &lt;br /&gt;
*Login: allow a user to sign in with her/his valid username and password. The authentication process happens by matching the username and password in the database, allowing the user access to the protected actions only if the given information matches the recorded values successfully. If not, the user will be redirected to the login page again.&lt;br /&gt;
*Access Restriction: create a session to hold the authenticated user ID after login, so navigation through additional protected actions can be done easily by just checking the userID in the current session.&lt;br /&gt;
*Logout: allow the user to sign out and set the authenticated userID in session file to nil.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Started ==&lt;br /&gt;
===Devise===&lt;br /&gt;
Devise is a flexible authentication solution for Rails helping developers save  time and effort while implementing authentication mechanisms from start. User authentication is a major component of most of the web applications, primarily to determine if the user is in fact, who it is declared to be. Devise is based on Warden&amp;lt;ref&amp;gt;https://github.com/hassox/warden/wiki&amp;lt;/ref&amp;gt;. (Customized [https://github.com/rack/rack Rack] middleware that provides authentication for rack applications). Rack can be considered a middleware between web server such as Mongreal, WEBrick and frameworks such as Rails, Sinatra. &amp;lt;br&amp;gt; &lt;br /&gt;
Current Version: 3.4.1&amp;lt;br&amp;gt;&lt;br /&gt;
First Release: 5 years ago&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Setup Devise===&lt;br /&gt;
Once you have created a Rails app using the &amp;quot;rails new &amp;lt;app name&amp;gt;&amp;quot; command we first need to add a line to the &amp;quot;Gemfile&amp;quot; using the following command:&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &amp;quot;gem 'devise'&amp;quot; &amp;gt;&amp;gt; Gemfile&amp;lt;/pre&amp;gt; &amp;lt;br&amp;gt; &lt;br /&gt;
And then install the gem using:&lt;br /&gt;
&amp;lt;pre&amp;gt;bundle install&amp;lt;/pre&amp;gt;&lt;br /&gt;
The Gem will be installed for your rails application. Then run the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:install          &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To create config files.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise user              &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To create model(User) class and routes and to also associate the 'User' model with 'Devise'.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rake db:migrate                        &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
To run the migration and create the table with certain fields appropriate for user authentication. The result should be something like: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrating ================================&lt;br /&gt;
-- create_table(:users)&lt;br /&gt;
   -&amp;gt; 0.0178s&lt;br /&gt;
-- add_index(:users, :email, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0010s&lt;br /&gt;
-- add_index(:users, :reset_password_token, {:unique=&amp;gt;true})&lt;br /&gt;
   -&amp;gt; 0.0055s&lt;br /&gt;
== 20150217043439 DeviseCreateUsers: migrated (0.0255s) =======================&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rails generate devise:views users      &lt;br /&gt;
&amp;lt;/pre&amp;gt;To create the directory /app/views/users with all the devise views, such as login form, registration form .&lt;br /&gt;
==Devise Methods==&lt;br /&gt;
Devise provides classes, models, views, controllers, views, helpers, routes. However, these functionality are exposed in only a small number of helper methods,   not all of these components would be required to know. Some of the important Devise helper methods provided are:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Method: authenticate_user!====&lt;br /&gt;
The &amp;lt;i&amp;gt;authenticate_user!&amp;lt;/i&amp;gt; method is a class method that can be called from a controller only. The method determines if the user has access to all or a specific set of controller actions. This method is invoked via a &amp;lt;i&amp;gt;before_filter&amp;lt;/i&amp;gt;, for example:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class UsersController &amp;lt; ApplicationController&lt;br /&gt;
  before_filter :authenticate_user!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;to make make any exceptions for accessing any actions without authentications we can update the above statement as:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
before_action :authenticate_user!, except: [:show]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In the above example, user authentication would be required to call any actions in the controller except the &amp;lt;i&amp;gt;show&amp;lt;/i&amp;gt; action. &lt;br /&gt;
So if the &amp;lt;i&amp;gt;root&amp;lt;/i&amp;gt; in the &amp;lt;code&amp;gt;config/routes.rb&amp;lt;/code&amp;gt; field is set to obtain any view belonging to the UsersController in this case, the Sign in page will be loaded before any of the actions can be accessed. &amp;lt;br&amp;gt; Once the user is authenticate, the required action is obtained.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: current_user====&lt;br /&gt;
The &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method is used to return the model class to whom the signed in user belongs. The method returns nil if a user has not yet signed in. &lt;br /&gt;
The &amp;lt;authenticate_user!&amp;gt; will make sure that the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method would never return &amp;lt;i&amp;gt;nil&amp;lt;/i&amp;gt;. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_signed_in?====&lt;br /&gt;
Checks if the &amp;lt;i&amp;gt;current_user&amp;lt;/i&amp;gt; method returns a non nil value. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: sign_in(@user) and sign_out(@user)====&lt;br /&gt;
The sign_in(@user) and the sign_out(@user) are useful to login or logout a newly created user.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Method: user_session====&lt;br /&gt;
This method returns metadata regarding the logged in user.&lt;br /&gt;
&lt;br /&gt;
==Devise Modules==&lt;br /&gt;
===Database Authenticatable===&lt;br /&gt;
Ensures that the user has entered the correct password and also to encrypt and stores the password in the database when the user registers for the first time. The authentication can be done both through POST requests or HTTP Basic Authentication.&amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).valid_password?('password123')         # returns true/false &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Omniauthable===&lt;br /&gt;
Adds OmniAuth (https://github.com/intridea/omniauth) support.&amp;lt;br&amp;gt;&lt;br /&gt;
===Confirmable===&lt;br /&gt;
Sends confirmation emails to Users following successful registration. This is to prevent bot registrations. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;User.find(1).confirm!      # returns true unless it's already confirmed&lt;br /&gt;
User.find(1).confirmed?    # true/false&lt;br /&gt;
User.find(1).send_confirmation_instructions # manually send instructions&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Recoverable===&lt;br /&gt;
Resets the user password and sends reset instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example:&amp;lt;/b&amp;gt; &amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;# resets the user password and save the record, true if valid passwords are given, otherwise false&lt;br /&gt;
User.find(1).reset_password!('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# only resets the user password, without saving the record&lt;br /&gt;
user = User.find(1)&lt;br /&gt;
user.reset_password('password123', 'password123')&lt;br /&gt;
&lt;br /&gt;
# creates a new token and send it with instructions about how to reset the password&lt;br /&gt;
User.find(1).send_reset_password_instructions &amp;lt;/pre&amp;gt;&lt;br /&gt;
===Registerable===&lt;br /&gt;
Handles signing up users through a registration process, also allowing them to edit and destroy their account.&amp;lt;br&amp;gt;&lt;br /&gt;
Helps user to register themselves and also to make changes to their login credentials including deleting their account. &lt;br /&gt;
===Rememberable=== &lt;br /&gt;
Cookie handling module to manage generating and clearing of tokens for remembering the user.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;User.find(1).remember_me!  # regenerating the token&lt;br /&gt;
User.find(1).forget_me!    # clearing the token&lt;br /&gt;
&lt;br /&gt;
# generating info to put into cookies&lt;br /&gt;
User.serialize_into_cookie(user)&lt;br /&gt;
&lt;br /&gt;
# lookup the user based on the incoming cookie information&lt;br /&gt;
User.serialize_from_cookie(cookie_string)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Trackable=== &lt;br /&gt;
Tracks login details for a specific user using log in count, last log in, IP address. These details help Site admin to investigate any unusual activity.&amp;lt;br&amp;gt; &lt;br /&gt;
===Timeoutable===&lt;br /&gt;
Expires sessions that have not been active in a specified period of time.&amp;lt;br&amp;gt;&lt;br /&gt;
===Validatable===&lt;br /&gt;
Provides validations of email and password to make sure that the log in details follow a given format. These can be modified to have customized validations.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Example :&amp;lt;/b&amp;gt;&amp;lt;pre&amp;gt;#email_required? ⇒ Boolean protected&lt;br /&gt;
#password_required? ⇒ Boolean protected&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Lockable===&lt;br /&gt;
Locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example applications ==&lt;br /&gt;
=== Devise and Rails&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
Rails 4.2 starter app with Devise for authentication.&lt;br /&gt;
====What is implemented====&lt;br /&gt;
&amp;amp;bull; Home page&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Navigation bar&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Sign up (create account)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Login&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Forgot password?” feature&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Remember me” (stay logged in) feature&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Edit account (edit user profile)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; List of users&amp;lt;br&amp;gt;&lt;br /&gt;
==== Installing ====&lt;br /&gt;
To build the example application, run:&lt;br /&gt;
&amp;lt;pre&amp;gt;rails new rails-devise -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will create a Rails app named &amp;lt;code&amp;gt;rails-devise&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
Then, select “Build a RailsApps example application”. After that, select”6) rails-devise”.&amp;lt;br&amp;gt;&lt;br /&gt;
As for additional preferences:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; If you plan to deploy to Heroku, select “Unicorn&amp;quot; as your production web server.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; Use “SQLite&amp;quot; for development on Mac or Linux. If you plan to deploy to Heroku, use “PostgreSQL&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; The example application uses the default “ERB” Rails template engine.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; If you are a beginner, for test framework, select “None”.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; if you choose either “Foundation&amp;quot; or “Bootstrap&amp;quot;, it will automatically install Devise views with attractive styling.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; “Gmail&amp;quot; is for development if you have one. if your site will be heavily used, then choose “SendGrid&amp;quot; or “Mandrill&amp;quot; for production.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; The example uses &amp;quot;Devise with default modules&amp;quot;.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Devise and Pundit and Rails&amp;lt;ref&amp;gt;https://github.com/RailsApps/rails-devise-pundit&amp;lt;/ref&amp;gt;===&lt;br /&gt;
It extends the rails-devise example application to add authorization with Pundit.&lt;br /&gt;
====What is implemented====&lt;br /&gt;
It adds authorization with Pundit, showing how to implement user roles, and limit access to pages based on user role.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an admin can see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an admin can change a user’s role&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t see a list of users&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t change their role&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can’t see (or edit) another user’s profile&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;bull; an ordinary user can see (and edit) their own user profile&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Installing====&lt;br /&gt;
To build the example application, run:&lt;br /&gt;
&amp;lt;pre&amp;gt;rails new rails-devise-pundit -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will create a new Rails app named &amp;lt;code&amp;gt;rails-devise-pundit&amp;lt;/code&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
Then, select “Build a RailsApps example application”. After that, select ”8) rails-devise-pundit”.&amp;lt;br&amp;gt;&lt;br /&gt;
The following steps are the same as Devise and Rails.&lt;br /&gt;
&lt;br /&gt;
==other Rails Authentication==&lt;br /&gt;
OmniAuth&amp;lt;ref&amp;gt;https://github.com/intridea/omniauth&amp;lt;/ref&amp;gt;: A generalized Rack framework for multiple-provider authentication.&amp;lt;br&amp;gt;&lt;br /&gt;
Authlogic&amp;lt;ref&amp;gt;https://github.com/binarylogic/authlogic&amp;lt;/ref&amp;gt;: A clean, simple, and unobtrusive ruby authentication solution.&amp;lt;br&amp;gt;&lt;br /&gt;
Restful-authentication&amp;lt;ref&amp;gt;https://github.com/technoweenie/restful-authentication&amp;lt;/ref&amp;gt;: Generates common user authentication code for Rails/Merb, with a full test/unit and rspec suite and optional Acts as State Machine support built-in.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Devise is the most popular Rails Authentication tools. It provides a full gamut of features, and can be configured to meet most requirements. Devise often interacts with Warden which does not provide helper methods, controller classes, views, configuration options and log in failure handling. All of these things are what Devise supplies. So if you need to extend or augment Devise, you may need to implement a customized Strategy class for your own.&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Savidhal</name></author>
	</entry>
</feed>