forked from jerryhoff/WebGoat.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hook up random lesson. A little too hard on the tutorial. Might need …
…to ease up on the RNG.
- Loading branch information
1 parent
5c51d78
commit ef4b578
Showing
4 changed files
with
111 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,78 @@ | ||
|
||
using System; | ||
using System.Web; | ||
using System.Web.UI; | ||
using OWASP.WebGoat.NET.App_Code; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace OWASP.WebGoat.NET.Content | ||
{ | ||
public partial class Random : System.Web.UI.Page | ||
{ | ||
} | ||
} | ||
private const uint MIN = 1; | ||
private const uint MAX = 1000; | ||
private const int INIT_NUMBERS = 5; | ||
|
||
public void Page_Load(object sender, EventArgs args) | ||
{ | ||
if (Session["Random"] == null) | ||
Reset(); | ||
|
||
IList<uint> numbers = (IList<uint>) Session["Numbers"]; | ||
lblSequence.Text = "Sequence: " + Print(numbers); | ||
} | ||
|
||
public void btnOneMore_Click(object sender, EventArgs args) | ||
{ | ||
WeakRandom rnd = (WeakRandom) Session["Random"]; | ||
IList<uint> numbers = (IList<uint>) Session["Numbers"]; | ||
|
||
numbers.Add(rnd.Next(MIN, MAX)); | ||
|
||
lblSequence.Text = "Sequence: " + Print(numbers); | ||
} | ||
|
||
public void btnGo_Click(object sender, EventArgs args) | ||
{ | ||
WeakRandom rnd = (WeakRandom) Session["Random"]; | ||
IList<uint> numbers = (IList<uint>) Session["Numbers"]; | ||
|
||
uint next = rnd.Peek(MIN, MAX); | ||
|
||
if (txtNextNumber.Text == next.ToString()) | ||
lblResult.Text = "You found it!"; | ||
else | ||
lblResult.Text = "Sorry please try again."; | ||
} | ||
|
||
public void btnReset_Click(object sender, EventArgs args) | ||
{ | ||
Reset(); | ||
|
||
IList<uint> numbers = (IList<uint>) Session["Numbers"]; | ||
lblSequence.Text = "Sequence: " + Print(numbers); | ||
} | ||
|
||
private string Print(IList<uint> numbers) | ||
{ | ||
StringBuilder strBuilder = new StringBuilder(); | ||
|
||
foreach(uint n in numbers) | ||
strBuilder.AppendFormat("{0}, ", n); | ||
|
||
return strBuilder.ToString(); | ||
} | ||
|
||
public void Reset() | ||
{ | ||
Session["Random"] = new WeakRandom(); | ||
|
||
var rnd = (WeakRandom) Session["Random"]; | ||
|
||
IList<uint> numbers = new List<uint>(); | ||
|
||
for(int i=0; i<INIT_NUMBERS; i++) | ||
numbers.Add(rnd.Next(MIN, MAX)); | ||
|
||
Session["Numbers"] = numbers; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.