Question: I save a bool value in NSUserDefaults like this:

```
[[NSUserDefaults standardUserDefaults]setBool:NO forKey:@"password"];

```

And then I synchronize defaults like this:

```
[[NSUserDefaults standardUserDefaults]synchronize];

```

But when my app enters background and then enters foreground my bool changes value to `YES`

Why does that happen ? I set my bool to `YES` only in one place in program, which is not managing when my app leaves/enters foreground.

Thanks!

Answer: 
Just perform a simple test where you are saving your bool as

```
[[NSUserDefaults standardUserDefaults]setBool:NO forKey:@"password"];
[[NSUserDefaults standardUserDefaults]synchronize];
NSLog(@"%d",[[NSUserDefaults standardUserDefaults] boolForKey:@"password"]);

```

see what's the value..
Make sure you have the right key string (`@"password"` in your case) when you retrieve the boolean value. It is case sensitive.

```
[[NSUserDefaults standardUserDefaults] boolForKey:@"password"];

```

Do a text search in your whole project for this key and you will find the offending code.